Common design Patterns in Java
design Pattern: pattern is a solution to the problem, it has been applied to a practical environment. And can be applied to other environments.
Classification of design Patterns:
- Distributed programming model,
- User interface mode,
- Data Model pattern three major categories.
the role of design patterns :
Design reuse, to provide a common vocabulary for the design, each model name is a design vocabulary, its concept makes the programmer's communication easier;
Using pattern vocabularies in your development documentation makes it easier for others to understand your ideas.
Classification of GOF Design patterns:
Classification by objective criteria:
1. Create: Creational is related to the creation of objects.
2. Structural type: Structural a combination of classes or objects.
3. Behavioral: Behavioral Describes how classes or objects interact and assigns responsibilities.
Create pattern
1. Abstract Factory mode Abstractfactory-"provides an interface to create a series of related or interdependent objects without specifying their specific classes.
2. Builder ModeBuilders--separates the construction of a complex object from his presentation, allowing the same build process to create different representations.
3. Factory mode Factory Method-Defines an interface for creating an object, letting subclasses decide which class to instantiate, and Factory to defer instantiation of a class to subclasses
4. Prototype Mode Prototype------Specifies the kind of object created with the prototype instance, and creates a new object by copying the prototypes.
5. Singleton mode Singleton-----guarantees that a class has only one instance and provides a global access point to access it
Structural mode
1. Adapter Mode Adapter------"Converts a class of interfaces into another interface that the customer wants, and the Adapter mode makes it possible for those classes to work together because the interface is incompatible.
2. Bridging modeBridge------separates the abstract part from its implementation, allowing them to change independently.
3. Combined mode Composite----------------"combining objects into a tree structure to represent a partial overall relationship, Composite makes the user consistent with the use of individual objects and composite objects
4. Decoration mode Decorator-----------------"dynamically adds some additional responsibilities to an object, and the Decorator mode is more flexible than generating subclasses in terms of the added functionality.
5. Appearance mode facade-"provides a consistent interface for a set of interfaces in a subsystem, Fa?ade provides a high-level interface that makes the subsystem easier to use
6. Enjoy meta-mode Flyweight--"
7. Agent ModeProxy--Provides a proxy for other objects to control access to this object
Behavioral patterns
1. Chain of responsibility Model Chain of Responsibility-----------gives multiple objects the opportunity to process requests, thus avoiding the coupling between the requested communicated and receiver
2. Order mode Command----encapsulates a request as an object, allowing you to parameterize the customer with different requests, queue requests and log requests, and support actions that can be undone
3. Interpreter Mode interpreter--"Given a language, defines a representation of his grammar, and defines an interpreter that uses that representation to interpret sentences in the language
4. Iterator mode Iterator--Provides a way to sequentially access individual elements of an aggregated object without exposing the object's internal representation.
5. Mediator Mode Mediatorobject interaction that encapsulates some columns with a mediation object
6. Memo Mode Mementocaptures the internal state of an object without destroying the object, and saves the state outside the object.
7. Observer Mode Observer---defines a one-to-many dependency between objects, and when an object's state changes, all objects dependent on it are notified of Automatic Updates
8. State mode state-allows an object to change his behavior when its internal state changes. The object seems to have changed his class.
9. Strategy Mode Strategy---Define a series of algorithms, encapsulate them one by one, and enable them to replace each other, this mode allows the algorithm to be independent of the customers who use them
10. Template Method Mode--"defines the skeleton of an algorithm in an operation, and delays some steps into subclasses, so that subclasses can redefine the algorithm to some specific steps without changing the structure of an algorithm," Templatemethod.
11. Visitor Mode Visitor---represents an action on elements in an object structure that allows you to define new actions that act on this element without changing the individual element classes
Common design Patterns in Java