In programming, we are usually need to queue requests, or decouple implementation of requests from its caller. And this is reason Command pattern was given birth. The Command pattern, basically, allows us encapsulate commands into objects. Thereby, it provides some useful options, such as:
- Queue or dequeue requests
- Parameterize client with different requests
- Support redo/undo functionality
The implementation of Command pattern is quite simple with four major terms: Receiver, Invoker, Command, ConcreteCommand and Client. Let take a look at bellow diagram: Continue reading
It is lucky because developers who are working on reSIProcate project created an openssl library on Android already. In order to integrate this library with reSIProcate we have to pull its source, and build them with ndk-build command. Continue reading
In order to ping connect host to guest, we need to add new network adapter, set it Bridged interface, and assign it an static IP address.
In this tutorial, my host runs Mac OSX and guest runs on Ubuntu server. Continue reading
Sometimes existing classes already provide functionalities required by client, but its interface is not what the client expects. So that we need a bridge to convert existing interface to what the client expects. And the bridge is called an Adapter. In real world, an adapter is very popular such as adapters for supplies, adapters for memory cards, so on. In software programming, the features of adapter are provided by Adapter pattern. We are going into its details in this article.
Adapter pattern helps us with two main jobs:
- Convert the interface of a class into another interface what client expects.
- Adapter lets classes work together, that couldn’t be able because of incompatible interfaces.
Sometimes we need to extend an object functionality, a normal way we can do it statically by inheritance mechanism. This is not wrong, but in some situations it makes source code more complex as well. That is reason Decorator pattern, a way of extending functionality dynamically, was born.
According to GoF, Decorator pattern is one of the widely used structure patterns. This pattern dynamically changes the functionality of an existed object at runtime without impacting on the existing functionality of the other objects. Continue reading
This article will explain how to install Python3 and virtual environment with virtualenv on Mac OS X. Normally, your Mac installed Python 2.7 already, you could remove it or keep both of them.
Before starting, make sure your Mac installed Xcode already. If not you can get it from Apple Store.
Next, we install Command line of Xcode through bellow command:
Before to be continue, I suggest that you should know about OOP Design Principles. If you do not any more, please take a look at this link before keep on reading this articles.
One of the design principles is “Dependency Inversion Principle”, it says that:
- High-level modules should not depend on low-level modules. Both should depend on abstractions.
- Abstractions should not depend on details. Details should depend on abstractions.
1. Open the Terminal
2. Create file .bash_profile
Updated on 25/11/2015: You should take a note about cookie with redirect-request. By default HttpURLConnection will take care about it automatically. You set your wide-system CookieManager, you pass a cookie to request, everything is OK.
But in case you have no default CookieManager and you do request without Cookie in header, you will get the problem. There’s no cookie was returned with response. This is because of HttpURLConnection set/get cookie for each request/response through the wide-system CookieManager instance. Let see bellow flow:
- Client sends a request without Cookie in header.
- Server returns a response which has code 301, new Localtion and Cookie inside header.
- HttpURLConnection looks at the header of response. It takes the Cookie then checks the global CookieManager instance. The instance if NULL then no cookie was saved.
- HttpURLConnection automatically make other request due to the Location. But because of no instance of CookieManager is available, then this request has no Cookie header too.
- Server receives the redirect request and sees no Cookie in header. It understands that no need to use Cookie mechanism. So it returns a request which has no Cookie.
To solve this problem, we can disable automatically process redirection by method setInstanceFollowRedirects(boolean) and do it by yourself. Notice that at step 3, you will extract Cookie header and set it to step 4 manually by setRequestProperty(String, String) and getHeaderField(String key).
As we know that Android 6.0 releases doesn’t support Apache HTTP client anymore. Instead of this, we will use the HttpURLConnection class. This API is more efficient, and in fact there are many interesting things to do with it. However today I only start with managing cookies. In that I will just focus on customize your own CookieStore. Continue reading
Builder pattern is an object creation design pattern, after the ealier one – Singleton. This pattern allows the client side create a complex object by specifing only its type and its content. In fact, we see builder pattern in something likes that: