|
|
DESIGN PATTERNS RAGA GEETHIKA
CONTENTS What are Design Patterns Why do we need Design Patterns Classification of Design Patterns Implementation Conclusion
INTRODUCTION “Gang of four”: Erich Gamma, Richard Helm, Ralph Johnson and John Vlissides Authors of Elements of Reusable Object-Oriented Software. Design patterns are recognized solutions to common problems. Design patterns are represented as relationships between classes and objects. The solution facilitates the development of highly cohesive modules with minimal coupling. Software professionals can immediately picture the high-level design in their heads when they refer the name of the pattern used to solve a particular issue when discussing system design.
DESIGN PATTERNS Creational Structural Behavioral Factory Abstract Factory Flyweight Singleton Builder Adapter Bridge Composite Decorator Facade Proxy Chain of responsibility Command Iterator Mediator Momento Observer State Strategy Visitor Template method
Factory method This pattern is used to create concrete class instances without specifying the exact class type Where its implemented. Define an interface for creating an object, but let the subclasses decide which class to instantiate. The Factory method lets a class defer instantiation to subclasses. Factory methods encapsulate the creation of objects. This can be useful if the creation process is very complex, for example if it depends on settings in configuration files or on user input.
Abstract Factory Provide an interface for creating families of related or dependant objects without specifying their concrete classes. A framework is created for creating sub-components that inherit from a common component. Ex: Central Government Rules (Abstract factory Class) Methods should have policy. Should have Courts. State1 Rules State2 Rules. All the methods are inherited from Abstract Factory class.
Flyweight pattern The flyweight pattern is used whenever you have large amount of small objects that share common information. The flyweight distinguishes between inner state (sometime called intrinsic state) and outer state (sometime called extrinsic state) of the object. The example include 3 parts – The flyweight factory (NumberFactory) The flyweight itself (Number) Flyweight concretes (One, Two, Three). Whenever a number is needed and isn't in the factory I build it and then return it in the GetNumber method.(Lazy loading)
Singleton pattern The Singleton Design Pattern ensures that only a single instance of a given object can exist. It does this by making the class constructor private so that it [the singleton itself] has full control over when the class instance is created. Ex: All Banking related. Builder Pattern The builder pattern describe a way to separate an object from it's construction. The same construction method can create different representation of the object. EX: When have a house contractor that is responsible to build the house in the right order. We have a builder abstract class that defines the interface for the concrete builders.
Adapter pattern Convert the interface of a class into another interface clients expect. Adpater lets the classes work together that couldn't otherwise because of incompatible interfaces Ex: Third Party Payment System Bridge Pattern The bridge pattern decouples an abstraction from its implementation so the two can vary independently. The pattern helps us whenever we need to select or switch the implementation at runtime.
Composite pattern Compose objects into tree structures to represent part-whole hierarchies. Composite lets clients treat individual objects and compositions of objects uniformly". Ex : SiteMap Decorator Pattern The Decorator patterns allows an objects behavior to be dynamically altered at runtime. This change in behavior is accomplished by wrapping an object with a new object. This new wrapper object is the Decorator. Ex: A simple example of a Decorator can be demonstrated with a report class. Some reports may need a header and some may also need a footer.
Facade pattern The Facade Design Pattern provides a simple interface and controls access to a series of complicated interfaces and or sub systems. A facade can reduce dependencies of outside code on the inner workings of a library, since most code uses the facade, thus allowing more flexibility in developing the system making the webservice acting as the Facade or the interface to many different dll's each representing a subsystem. Proxy Pattern Provides a surrogate or placeholder for another object to control access to it Ex: enable caching on an ASP.net page
Conclusion http://en.wikipedia.org/ http://www.asp.net/ http://blogs.msdn.com http://msdn.microsoft.com
| URL: |
No comments posted yet
Comments