Design Patterns
|
|
|
A design pattern is a recurring solution to a standard problem.
The most well-known design patterns (in total 23) were documented by Erich Gamma, Richard Helm, Ralph Johnson, John Vlissides also called The Gang of Four (GOF) in the book Design Patterns -- Elements of Reusable Software (1995).
There a hunderds of design patterns described in the literature. This tutorial only describes the design patterns documented by the GOF.
The GOF has divided the design patterns into three types.
Creational patterns
|
Deal with initializing and configuring classes and objects
- Abstract Factory
- Builder Factory
- Factory Method
- Prototype Factory
- Singleton
|
Structural patterns
|
Deal with decoupling interface and implementation of classes and objects
- Adapter
- Bridge
- Composite
- Decorator
- Facade
- Flyweight
- Proxy
|
Behavioral patterns
|
Deal with dynamic interactions among societies of classes and objects
- Chain of Responsibility
- Command
- Interpreter
- Iterator
- Mediator
- Memento
- Observer
- State
- Strategy
- Template
- Visitor
|
Creational patterns.
Factory Method |
Method in a derived class creates associates |
Abstract Factory |
Factory for building related objects |
Builder |
Factory for building complex objects incrementally |
Prototype |
Factory for cloning new instances from a prototype |
Singleton |
Factory for a singular (sole) instance |
|
knowledge of pattern
# creational
1. factory method: lazy initialize specific instance
2. abstract factory: supply a interface for the system
3. builder: builder or create a object apart from its descrition
4. prototype: create new object which type base on the type of specific instance
5. singleton: make sure one class only have one instance, supply for every visitor
allways used with factory pattern together.
# structural
6. adapter: give a interface of class for get another required interface, implement compatibility
7. bridge: extranet abstract class from implement class, make it suit for their single change
public abtract class AbstractRoot
{
operation();
}
8. composite: make a object as tree structure, make "part-all" clearly.
组合模式: ----继承
9. decorator: change extend(8) to delegate
装饰器模式: --- 委托
10. facade: supply a interface for visiting the sub-system
11. flyweight: it seem logic like cache.
if (flyweight[key] exists)
{
return existing flyweight;
}
else
{
create new flyweight;
add it to pool of flyweights;
return the new flyweight;
}
12. proxy: a, remote proxy visit
b, virtual proxy performance
c, protection proxy control
d, smart reference get reference number
# behavioral
13. interpreter 解释模式
14. Template Method 模版模式
AIM: 定义一个操作中的算法的骨架,而将一些步骤延迟到子类中。
ENV: 一次性实现一个算法的不变的部分,并将可变的行为留给子类来实现.
TODO: 比较组合模式
15. Chain of Responsibility
AIM: 使多个对象都有机会处理请求,从而避免请求的发送者和接收者之间的耦合关系。将这些对象连成一条链,并沿着这条链传递该请求,直到有一个对象处理它为止.
有多个的对象可以处理一个请求,哪个对象处理该请求运行时刻自动确定。
你想在不明确指定接收者的情况下,向多个对象中的一个提交一个请求。
可处理一个请求的对象集合应被动态指定。
16. Command 命令模式
将一个请求封装为一个对象,从而使你可用不同的请求对客户进行参数化;对请求排队或记录请求日志,以及支持可撤消的操作。
17. Iterator 迭代模式
18. Mediator 仲裁模式
19. Memento 记忆模式
20. Observer 观察者模式
21. State 状态模式
允许一个对象在其内部状态改变时改变它的行为。对象看起来似乎修改了它的类。
22. Strategy 策略模式
TODO: 比较State
定义一系列的算法,把它们一个个封装起来, 并且使它们可相互替换。本模式使得算法可独立于使用它的客户而变化。
23. Vistor 访问模式
<head first ooad>
感觉OO原则其实我们平时编码的最基本原则, 设计模式可以就是遵循的OO原则来运用的.
OO principle
#1 the open-closed principle(ocp)
classed shoulde be open for extension, and closed for modification.
#2 the don't repeat yourself principle (DRY)
have each piece of imformation and behavior in your system in a single,sensible place.
#3 the single responsibility principle(SRP)
Single responsibility priciple correctly when each of your objects has only one reason to change
#4 the Liskov substitution priinciple(LSP)
感觉LSP就是用委托....
分享到:
相关推荐
But there is more power waiting to be unlocked--JavaScript is capable of full object-oriented capabilities, and by applying OOP principles, best practices, and design patterns to your code, you can ...
Knowing about design patterns enables developers to improve their code base, promoting code reuse and making their design more robust. This book focuses on the practical aspects of programming in ...
PHP 5 dvanced OOP and Design Patterns,英文版,PDF格式
This book is fast and simple way to get the idea behind each of the 29 popular design patterns. The book is not tied to any specific programming language and will be good for you as long as you have a...
Design Patterns in Modern C++. Reusable Approaches for OOP Design.
Oracle's training on OOP and design patterns
Professional ASP.NET Design Patterns will show you how to implement design patterns in real ASP.NET applications by introducing you to the basic OOP skills needed to understand and interpret design ...
Object-oriented programming (OOP) and design patterns are not new to the field, but can often be overlooked in their value. They are, at times, not only overwhelming to learn, but difficult to put ...
The topic of Design Patterns sounds dry, academically constipated and, in all honesty, done to death in almost every programming language imaginable—including programming languages such as JavaScript...
oriented programming texts that teach readers how to program in C++ with standard I/O (e.g., Deitel) and the relatively few books that assume a knowledge of OOP/C++ and emphasize GUI programming using...
demonstrates the hand-in-hand relationship of OOP and design patterns. The beginning chapters of this book discuss and detail OOP principles, and while some aspects may be review, all will be ...
you’ll learn about advanced topics such as working with static methods and properties, abstract classes, interfaces, design patterns, exception handling, and more. You’ll also be exposed to key ...
Professional ASP.NET Design Patterns will show you how to implement design patterns in real ASP.NET applications by introducing you to the basic OOP skills needed to understand and interpret design ...
了解OOP和FP范例 探索传统的Java设计模式 了解Java的新功能特性 了解设计模式如何被新功能改变和影响 了解什么是React式编程,以及为什么它是FP的自然扩展 如果您觉得这本书适合您,请立即获取! 说明和导航 所有...
ArquiteturaDeSoftware:软件仓库,com OOP,SOLID,Clean Code,Design Patterns等的存储库
Data Structures and Algorithms with Object-Oriented Design Patterns in CPlusPlus - Bruno R. Preiss Data Structures and Algorithms with Object-Oriented Design Patterns in CSharp - Bruno R. Preiss Data ...
the working of all magic methods, and the importance of effective PHP OOP concepts, which will enable you to write effective PHP code. You will find out how to implement design patterns and resolve ...
我们从经典的面向对象编程(OOP)技术开始,通过将OOP和函数式编程相结合来增强实现,最后到React式编程模型,在该模型中,函数式编程和OOP协同使用以编写更好的代码。 在本书的最后,我们将向您展示如何处理体系...
设计模式简介简介《大话设计模式》中的设计模式以及由C#实现的一些示例。 《大话设计模式》中设计模式总结,示例代码基于C#写的,基于.NET Core如果要自己编译请.NET Core SDK设计模式设计原则单一职责原则对于一...