Favor composition over inheritance. (Has-a instead of Is-a)
HAS-A can be better than IS-ACreating systems using composition gives you more flexibility. Not only does it let you encapsulate a family of algorithms into their own set of classes, but it also lets you change behavior at run-time as long as the object you're composing with implements the correct behavior interface.
Composition is used in many design patterns.
No comments:
Post a Comment