160 likes | 172 Views
Learn about design patterns based on object-oriented programming principles and how they provide solutions for recurring problems. Explore the advantages and types of design patterns, along with relationships between them. Understand the benefits, drawbacks, and suggestions for effectively using design patterns in software development.
E N D
A pattern is based on the principles of object-oriented programming: abstraction, inheritance, polymorphism and association • A pattern is a recurringsolutionto a standard problem, in a context • A pattern is independent of the application domain • A pattern is a three-part rule, which expresses a relation between a certain context, a problem, and a solution Pattern??
Using patterns offers a few key advantages: • Promote reuse • Facilitate a proven solution • Provide a common vocabulary • “Design patterns help a designer get a design right faster” Design Pattern Advantages
Creational patterns • Focus on the best way to create instances of objects to promote flexibility • Structural patterns • Focus on the composition of classes and objects into larger structures • Behavioral patterns • Focus on the interaction between classes or objects • Distribute responsibility Types of Patterns
Some patterns are used together, for example the composite pattern is sometimes used with the iterator or visitor • Some patterns are also defined as alternatives for others, e.g. the prototype pattern can be used as an alternative to the abstract factory pattern • Some patterns, e.g. the composite and decorator pattern, result in similar designs Relationships between Patterns
Abstract Factory • Factory for building related objects • Builder • Separates an object construction from its representation • Factory Method • Creates an instance of several derived classes • Prototype • Factory for cloning new instances from a prototype • Singleton • A class of which a single object can exist Creational Design Patterns
Adapter • Match interfaces of different classes • Bridge • Separates an object’s interface from its implementation • Composite • A tree structure of simple and composite objects • Decorator • Add responsibilities of objects dynamically • Facade • A single class that represents the entire subsystem Structural Patterns
Flyweight • A fine-grained objects shared efficiently • Proxy • An object representing another object Structural Patterns (cont.)
Chain of Responsibility • Passes a request between a chain of objects • Command • Encapsulates a command request as an object • Iterator • Elements of a collection are accessed sequentially • Interpreter • Language elements are included • Mediator • Defines simplified communication between classes Behavioral Patterns
Memento • Capture and restores an object’s internal state • Observer • A way of notifying change to a number of classes • State • Alter an object’s behavior when its state changes • Strategy • Encapsulates an algorithm inside a class • Template Method • Defer the exact steps of an algorithm to a subclass Behavioral Patterns (cont.)
Visitor • Defines a new operation to a class without change Behavioral Patterns (cont.)
Design patterns enable large-scale reuse of software architectures and also help document systems • Patterns help improve developer communication • Pattern names form a common vocabulary • Patterns help ease the transition to Object Oriented technology Benefits of Design Patterns
Patterns do not lead to direct code reuse • Patterns are deceptively simple • Teams may suffer from pattern overload • Patterns are validated by experience and discussion rather than by automated testing • Integrating patterns is a human-intensive activity Drawbacks of Design Patterns
Obtain an overview of the pattern • Obtain an understanding of the classes and objects and relationships between them • Choose application-specific names for the components of the patterns • Define the classes • Choose application-specific names for the operations defined in the pattern • Implement the necessary operations and relationships Suggestions for Effective Use