Design_pattern_AspNet_part4

来源:互联网 发布:js求二维数组的最大值 编辑:程序博客网 时间:2024/04/30 14:01

Factory Method

 

Hide Complex Logic Of Creating Objects

 



                                                                                                                                                                              

Example :

 

 


Decorate

 

Change Behaviour dynamically

 

 


 

 

 

Example :

 

 

 

 

Template Method

Base class Have a template steps , only few difference ,provide them as virtual using sub class implement .

 

 

Example :


 


We Can See, Weekday is very boring !  :), hope weekend coming soon !

 

 

 

 

 

State

 

Separate State logic into different classes.

 

Sample :

 

 

 

 


Strategy

 

Change strategy dynamically .

 

Sample



 


Remember 3 principles:

 

1.     Dependency Injection(Construction , Method , Setter )

2.     Interface Separate

3.     Liskov Replace 

原创粉丝点击