1. 程式人生 > >不同設計模式解決的問題(完善中。。)

不同設計模式解決的問題(完善中。。)

具體的設計模式,網上有很多介紹。本人蔘見 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