Tag Archives: design pattern

Applying Command pattern in a demo of undoable actions.

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

Builder pattern

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:

Builder pattern demo Continue reading

Singleton pattern

Sometimes we need only one instance of a class in whole system, and “Singleton” was born.

Singleton is the simplest pattern in the design pattern world. It invokes only one class which is responsible to instantite itself, to make sure no more than one instance of it was created. This class is used for centralized management of resources and provides global access point to itself. Continue reading