The best Introduction to Design Patterns Tutorial In 2024, In this tutorial you can learn What is the GOF (Gang of Four, spelling Gang of Four)?,The use of design patterns,Types of design patterns,Six principles of design patterns,
Design patterns (Design pattern) represents a best practice, it is often adopted by experienced object-oriented software developers. Design patterns are solutions to common problems of software developers in the software development process in the face. These solutions are many software developers through quite a long period of trial and error summed up.
Design patterns are set to be used repeatedly, most people know, after cataloging, code design experience summary. Use design patterns to reuse code, make the code easier to understand others, to ensure the reliability of the code. Undoubtedly, design patterns have on others in the system are win-win, design patterns makes code compiled real engineering, design patterns is the cornerstone of software engineering, as building a brick stone same. Project rational use of design patterns can be the perfect solution to many problems, each mode corresponding to the principle of reality have corresponding, each mode describes a constantly recurring problem around us, as well as the problem core solution, which is widely used design patterns that can be the reason.
1994 by Erich Gamma, Richard Helm, Ralph Johnson and John Vlissides four co-published a book calledDesign Patterns - Elements of Reusable Object- Oriented Software ( Chinese translation: Design Patterns - Reusable Object-Oriented Software element)the book that first mentioned the concept of software development design patterns.
Four authors collectivelyGOF (Gang of Four, spelling Gang of Four).They proposed design model is mainly based on object-oriented design principles.
Design Patterns in software development for two main purposes.
Design pattern provides a standard terminology system, and in particular to a specific scene. For example, a single design pattern implies the use of a single object, so that all are familiar with singleton design pattern developers can use a single object, and can tell each other this way, the program uses the singleton pattern.
Design patterns have evolved over a long period of time, they provide the best solutions to common problems faced by the software development process. These learning mode helps inexperienced developer through a quick and easy way to learn the software design.
According to the reference book of design patternsDesign Patterns - Elements of Reusable Object- Oriented Software ( Chinese translation: Design Patterns - Object-oriented software elements reusable)mentioned, a total of 23 design patterns. These patterns can be divided into three categories: create schema (Creational Patterns), structural model (Structural Patterns), type of model (Behavioral Patterns). Of course, we will discuss another type of design patterns: J2EE design patterns.
序号 | 模式 & 描述 | 包括 |
---|---|---|
1 | 创建型模式 这些设计模式提供了一种在创建对象的同时隐藏创建逻辑的方式,而不是使用新的运算符直接实例化对象。这使得程序在判断针对某个给定实例需要创建哪些对象时更加灵活。 |
|
2 | 结构型模式 这些设计模式关注类和对象的组合。继承的概念被用来组合接口和定义组合对象获得新功能的方式。 |
|
3 | 行为型模式 这些设计模式特别关注对象之间的通信。 |
|
4 | J2EE 模式 这些设计模式特别关注表示层。这些模式是由 Sun Java Center 鉴定的。 |
|
Here with a whole picture to describe the relationship between design patterns:
1. Open Closed Principle (Open Close Principle)
Open Closed Principle means: open for extension, but closed for modification. When the program needs to expand, not to modify the original code to achieve the effect of a hot-swappable. In short, in order to make the program's scalability, ease of maintenance and upgrades. Want to achieve this effect, we need to use interfaces and abstract classes, concrete design later we will mention this point.
2, Richter substitution principle (Liskov Substitution Principle)
Richter substitution principle is one of the basic principles of object-oriented design. Richter substitution principle that where any base class can appear, subclasses will be able to appear. LSP is inherited cornerstone multiplexed only when the derived class can replace the base class, and functional software unit is not affected, the base class can really be reused, and the derived class can be the basis of the base class adds new behavior. Richter substitution principle is the principle of complementarity of opening and closing. The key step is the realization of the principle of opening and closing abstraction, inheritance and base class and subclass of the abstract concrete realization, so Richter substitution principle is abstract concrete steps to implement the specification.
3. Dependency Inversion principle (Dependence Inversion Principle)
This principle is the basis of the principle of opening and closing, the specific content: For programming interfaces, depending on the abstract does not depend on specific.
4, Interface Segregation Principle (Interface Segregation Principle)
Meaning of this principle is: the use of multiple isolated interface is better than using a single interface. It also has another meaning: to reduce the degree of coupling between classes. Thus, the fact that design patterns starting from large-scale software architecture, easy to upgrade and maintain the software design, which emphasizes reducing dependence, reducing the coupling.
5, Demeter, also known as the least known principles (Demeter Principle)
Minimum know principle means: an entity should interact as little as possible between other entities, making the system relatively independent function modules.
6, synthesis multiplexing principles (Composite Reuse Principle)
Synthesis multiplexing refers to the principle: as much as possible the use of synthetic / polymeric way, instead of using inheritance.