Posts

Showing posts from November, 2011

Design Pattern : behavioural

Chain of responsibilityThe purpose for this is for high cohesion. This means, to increase the reusability.This can be visualized with the specialization in manufacturing world. Each function performs specialized task, and chained together to perform a bigger task.These functions can be reused in other scope since they are doing specialized and simpler task.CommandThis is to encapsulate requests.Thus, for a program to call any command, it has the similar interface.InterpreterThis will translate the context passed by client and perform necessary task on it.IteratorThis to enable to parse through the whole data structure.MediatorAs a middle man between 2 sub-program to enable low coupling, or for decoupling purpose.MomentoThis is to capture the state of the class and stored in another objectGood for undo to restore the object to its previous stateObserverIt’s for event driven.As listener, or “don’t call me, I’ll call you” (After reading the online notes, I am not convinced by what was to…

Design Pattern : structural

CompositeIt looks like tree structure, the end node is called leaf.All the node has uniform interface, thus they can be used/called via uniform operation/data structureAdaptorThis is using another class to encapsulate the class to be accessed. Thus the caller will see/use the same interface regardless on how the class to be assessed being implemented.proxyThis is acting as a middle man to handle the client requests and sever response.Fa├žadeThis is using an interface to reduce the complexity.It packages the objects and methodsDecoratorThis is for dynamically to add new responsibility / variation on the methodsIt will hold the base class pointer, and the real implementation on the child class or actual object.BridgeThis is acting like multi-purpose adapter.It serves for multi-platform.FlyweightIt handles the pool of resources that are shared by the clients.Private Class Data This is to put the private and readonly data into a class, and being initialized by construtor.

Design Pattern : creation

Singletonthis is basically suitable for single instance through out the program.it can contains the static variables used by the program.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.FactoryThe factory is a class to hold and control the creation of the class objects.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.Abstract FactorySimilar to Factory type, but the factory is an abstract class.This is good for multi-platform support, where the right factory will be instantiated based on the platform.BuilderThis is to hide the complexity of the object by the builder.The program can have multiple builder with same operation but different methods.There is a “directory” to call the right builder to call for operation to produce “product”.PrototypeUsing abstract class to forc…

OO concept and software development practices

I attended a 5-day Design Pattern class last year, and the summary that I published then, was the initial thought of this k-db site. I am revising them and put them here. :)

Day 1 : OO concept and software development practices
OO concept revised.Normally these are discussed :inheritancecompositionencapsulationpolymorphismDiscussed in class :abstractionencapsulationgeneralizationspecializationType of errorscompilationsyntaxcontextuallinkingruntimelogicalExample to show the best way to code to avoid error :if (x == 0)if (0 == x) <– using this coding style, missing a "=" in the condition statement will alarm error during compilation.Why it is a good practice to use static for variable declaration?for information hiding.so people won’t use extern to access to it in other file, to ensure the value is not overwritten by unknown.error prone during linking.Software quality measurement :reusability : code, function, user experience (dialogue box/interface), software pattern can be …