Westward Look design pattern study notes

 

Simple factory pattern :

  Create a factory class, Factory, internal Factory has create method, to produce the corresponding implementation class entities the external entity returns generally inherits the abstract class or implements the interface, create a method that is returned is abstract and implementation, client these entities will be able to use the interface classes , may be added to achieve the appropriate class can be reflected so that the open extension but closed for modification, engineering mode also reflects the single responsibility, because each entity implementation class, to achieve separately a function that can affect it on a factor (pretty much used local) method implemented externally, as well as rely on reverse

 

Strategy Mode :

  The difference is that with the factory pattern, factory pattern needs to know the interface type, model and strategy is not in use, more suitable for those interface classes are defined in many ways irrelevant entity, need to block out some use

 

Single Responsibility :

  Only one external factors that can influence the behavior of this class (which I usually pay attention to the application)

 

Open Closed Principle :

  Open for extension, closed for modification (which I usually pay attention to the application)

 

Rely on the reverse principle :

  Do not depend directly on the upper lower, they depend directly on the level of abstraction, the abstract does not depend on implementation, implementation depends abstract

 

 

Proxy mode :

  A class A is a direct access to the original class B now through a proxy mode, the generated class B proxy class ProxyB, Class B, and proxy class ProxyB generally inherited or implement certain interface and implementation class , ProxyB holds class B of example, so that you can call before classes B, do some intercepted or check process

 

Factory Method pattern :

  Simple factory pattern and the biggest difference is choosing what plants to achieve the upper class to be processed, basically have not seen a similar use, it should be less common

 

Prototype mode:

  Prototype mode key insight is deep copy and shallow copy of the issue, create an instance of the type specified by the original object, and create new objects by copying the prototype (string is a special characteristic has a value type of reference type)

 

Template Method:

  Refining common code, reduce duplication of definitions (I usually use the back)

 

 

 

 

Guess you like

Origin www.cnblogs.com/622698abc/p/11106743.html