Questions tagged «strategy-pattern»

5
我们可以使用策略模式和依赖注入完全取代继承吗?
例如: var duckBehaviors = new Duckbehavior(); duckBehaviors.quackBehavior = new Quack(); duckBehaviors.flyBehavior = new FlyWithWings(); Duck mallardDuck = new Duck(DuckTypes.MallardDuck, duckBehaviors) 由于Duck类包含所有行为(抽象),因此似乎不需要创建新类MallardDuck(扩展了Duck)。 参考:Head First设计模式,第1章。
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.