Thursday, November 3, 2011

Design Pattern : creation

  1. Singleton
    1. this is basically suitable for single instance through out the program.
    2. it can contains the static variables used by the program.
    3. the benefits for this versus global variable is for data encapsulation purpose. You can have accessor and modifier functions as a guarding to set or read the variable.
  2. Factory
    1. The factory is a class to hold and control the creation of the class objects.
    2. The object class held by factory is the base class, thus any of the child class object can be instantiated, and transparent in the main program.
  3. Abstract Factory
    1. Similar to Factory type, but the factory is an abstract class.
    2. This is good for multi-platform support, where the right factory will be instantiated based on the platform.
  4. Builder
    1. This is to hide the complexity of the object by the builder.
    2. The program can have multiple builder with same operation but different methods.
    3. There is a “directory” to call the right builder to call for operation to produce “product”.
  5. Prototype
    1. Using abstract class to force the functions overidding (enforcement on the child classes)
    2. Thus the child classes need to have the implementation for the functions specified by the base class (the prototype abstract class)

No comments:

Post a Comment