HeadFirst design pattern <2>

HeadFirst design pattern <2>

1 decorator pattern

../_images/Decorator.jpg

../_images/seq_Decorator.jpg

Starbucks Coffee

Drink

1574694357027

1574694374349

1574694551953

1574694577631

1574694602783

1574694622129

1574694652428

1574694677058

1574694691813

1574694715899

1574694741032

to sum up

If the policy mode is achieved by a combination of elasticity, then the decorator pattern is to be achieved through inheritance, at the same time to achieve, customers using the basic feel of the decorator pattern

2 adapter mode

Object Adapter

../_images/Adapter.jpg

Class Adapter

../_images/Adapter_classModel.jpg

../_images/seq_Adapter.jpg

Turkey

1574695113932

1574695124646

1574695148257

1574695162581

1574695174994

1574695190474

1574695228749

to sum up

Decorator Pattern and the Adapter pattern very much like, adapter mode is the adaptation object interface, and the new responsibilities objects to the case of the decorator pattern does not change the object's interface.

Guess you like

Origin www.cnblogs.com/lovexinyi/p/11932161.html