(According to the msdn webcast courses)
This is a behavior-oriented design model that is widely used.
Objects may often need different typesAlgorithm, But if the change is frequent, the type will become very fragile.
As shown inCubeTake, take different cross sections, then its area calculation method will be different, need to use different algorithms.
So, how can we design Algorithms Dynamically without changing the method during runtime? Decouples algorithms from objects for dynamic loading.
In C #, the following technical means can be dynamically loaded to support runtime changes:
Virtual functions, interfaces, delegation, reflection
Gof: defines a series of algorithms, encapsulates them one by one, and enables them to replace each other. This pattern allows the algorithm to be independent of the changes in the customer system using it.
An example with no rule mode adopted:
After the policy mode is adopted, the algorithm policy and the specific object are separated, so that different algorithms can be implemented by inputting different policy objects in the same object, this allows you to dynamically change the algorithm.
<End>