220 likes | 228 Views
Learn about the definition, history, and benefits of design patterns in software design. Explore different creational, structural, and behavioral patterns. Improve code quality and development efficiency.
E N D
Design Patterns • Supada Laosooksathit
Content • Definition • History • Benefits • Classification
Definition • Reusable solution to a standard reoccurring problem • Template for a problem that can be used in many different situations • Deal with problems at the level of software design
History • Christopher Alexander • Originated as an architectural concept • Kent Beck and Ward Cunningham • presented the idea of applying patterns to programming at OOPSLA conference (1987) • Gang of Four • Eric Gamma, Richard Helm, Ralph Johnson, John Vlissides • published “Design Patterns: Elements of Reusable Object-Oriented Software”
Benefits • Speeds up the development process • Provides solutions documented in a typical format • Prevents subtle issues that can cause major problems • Improves code readability because of the patterns • Makes communication between designers more efficient
Classification • Creational Patterns • Structural Patterns • Behavioral Patterns
Classification • Creational Patterns • Structural Patterns • Behavioral Patterns
Creational Patterns • Abstract Factory • Provides an interface for creating families of objects • Provides a way to encapsulate a group of individual factories that have a common theme • Factory Method • Defines an interface for creating objects • Lets subclasses decide which class to instantiate
Creational Patterns • Builder • Separate the construction of a complex object from its representation • The same construction process can create different representations • Object Pool • A set of initialized objects that are kept ready to use • Client requests an object, operates and returns to the pool • Effective when the cost of initializing a class instance is high
Creational Patterns • Prototype • Creates a clone of object • Avoid creation a costly new one • Singleton • Restrict instantiation of a class to one object
Classification • Creational Patterns • Structural Patterns • Behavioral Patterns
Structural Patterns • Adapter • Allows classes work together by wrapping an existing class with a new interface • Bridge • Separate the interface from it implementation • Separate responsibilities into different classes • Those classes can vary independently
Structural Patterns • Composite • Allows a group of objects to be composed into tree structures • Represent part-whole hierarchies • Decorator • Attaches new or additional behavior and functionality to an object
Structural Patterns • Facade • Provides a simplified interface to a large body of code • Flyweight • Describes how to share objects to avoid creating a large number of objects • Proxy • Provides a holder for another object to control access to it • Add a wrapper and delegation to protect a real component
Classification • Creational Patterns • Structural Patterns • Behavioral Patterns
Behavioral Patterns • Chain of Responsibility • Chain the receiving objects and pass the request behavior along the chain until an object handles it • Command • Encapsulates a request as an object • Object is used to represent actions
Behavioral Patterns • Interpreter • Defines a grammatical representation for a language • Interpret sentences in the language • Iterator • Provides a common interface for iterating through collections without bothering about underlying implementation
Behavioral Patterns • Mediator • Deals with the complexity of classes increase • Keep objects from referring to each other • Allows objects’ interaction be varied independently • Memento • Provides the ability to restore an object to its previous state
Behavioral Patterns • Observer • When one object changes state, all dependents are notified and updated automatically • State • Allows an object to alter its behavior when its internal state changes
Behavioral Patterns • Strategy • An object and its behavior are separated and put into two different classes • Allows the algorithm changeable anytime • Template Method • Set up the skeleton of an algorithm in an operation
Behavioral Patterns • Visitor • Defines a new operation to be performed on the elements of an object structure • No change of the element classes