open-close principle -
- open for extension and closed for modification.
- example in strategy, we expose all the behaviors using interface. In future if we want to modify any behavior, or want to add any new behavior, we can do it, because we are calling interface(open for extension) not the concrete class object. The user class will not have to modify anything to achieve this(close for modification).
double dispatch-
- 2 calls to complete an operation.
- an object provides its own instance to some other class to get operated on it.
- Example - patient goes to doctor and then doctor operates on him.
This is what happens in visitor pattern. object of visitor is passed to the class, from there it calls visit method to get its functionality done.
- open for extension and closed for modification.
- example in strategy, we expose all the behaviors using interface. In future if we want to modify any behavior, or want to add any new behavior, we can do it, because we are calling interface(open for extension) not the concrete class object. The user class will not have to modify anything to achieve this(close for modification).
double dispatch-
- 2 calls to complete an operation.
- an object provides its own instance to some other class to get operated on it.
- Example - patient goes to doctor and then doctor operates on him.
This is what happens in visitor pattern. object of visitor is passed to the class, from there it calls visit method to get its functionality done.
No comments:
Post a Comment