具体的设计模式,网上有很多介绍。本人参见 journaldev
| 模式 | 解决问题 |
|---|---|
| Builder | Too Many arguments to pass from client program to the Factory class |
| Factory | when we have a super class with multiple sub-classes and based on input, we need to return one of the sub-class |
| Prototype | When u need clone an existing object (shallow or deep copy) |
| Strategy | Define multiple algorithms and let client application pass the algorithm to be used as a parameter |
| Decorator | modify the functionality of an object at runtime |
| Composite | When we need to create a structure in a way that the objects in the structure has to be treated the same way |
| Bridge | Using abstract class replacing implement class to decouple |
| Facade | Unify a set of interfaces in a subsystem |
| Template method | define common functions in abstract class for all sub class |
本文介绍了多种设计模式,包括Builder、Factory、Prototype等,并解释了它们各自解决的问题:如Builder模式解决客户端程序向工厂类传递过多参数的问题;Factory模式用于根据输入返回子类之一;Prototype模式用于克隆现有对象;Strategy模式定义了一系列算法供客户端选择使用。
2996

被折叠的 条评论
为什么被折叠?



