Today I would like to relate to a little research i have done on my
daily job. These abstracts will provide a path for us on the road
to further investigate these patterns. Also a turkish version of
this work will be published too.
Recommended GOF Patterns 1 - Abstract Factory Abstract factory creates factories that produces different classes. For example if we need a factory that either creates win buttons or osx buttons, we need a factory to create these factories. Here we need to define what factory is by the way : if we have more than one adapters for example, we need to know which one to create in a given situation, but if we give this responsibility to any class in the system, we improve the dependency of each object to another, so we need another class to handle this responsibility. This class is the factory class. 2 - Factory Method This pattern is used to put the creation method to the class which will use the created object 3 - Singleton Singleton pattern is used to create the factory itself . To implement a singleton pattern you have to define the constructor as private and create a static method for the class that cannot be overridden. This static method will return an object of the class. 4 - Adapter Main function is to change the interface of a class to match other classes, for example, there may be more than one outside class that does the same operation for our system but we don't want to change the inner classes according to the outer class that we use so we create adapters for each class and provide the same interface to our inner classes, so the inner classes dont have to know which class they are dealing with.
5 - Composite Sometimes an object should not know about the way a method works. For example an object may work with a single other object to accomplish some task and some other time the same object may require to work with multiple objects to do the same task. If the implementor object knew about the objects it works, this reduces low-coupling and flexibility. In order to overcome this problem we use composite pattern. A class is constructed with same interface as the other classes, and the multiple objects work in that class, so all other objects dont know anything about the sub objects that does the work. 6 - Facade This pattern is used to hide complexity of a system (either inside or outside) from other parts of the system. For example you want to hide business logic from representation logic because the representation can change any time but business logic is more stable. So a facade class is constructed to centralize the operations done on a complex subsystem. 7 - Observer This pattern is used when a change of state in a class requires the attention of many other classes. If we write a function for every class about the change, we have a highly coupled class system and it will be very hard to make a change in the class that does the changes. So in Observer pattern as a solution to this problem an interface is created, and the classes that want to learn about the change, implements this interface. 8 - Strategy Over time an object may require different kinds of ways to do the same operation. This can be examplified by a a discount method, some conditions require different discount methods, and some other conditions require different methods. In order to cope with the complexity this problem presents, we use the strategy pattern. In strategy pattern, a method is abstracted using an interface. Then different strategies are implemented using this interface. As a result, implementor class knows nothing of the strategy class, it just uses the specified interface.