Designing for Reuse
摘要
OneDesigning for reuseabout of the strongest motivations for adopting an object-oriented approach is the facility for reuse. All object-oriented languages provide two mechanisms for reuse: compositionComposition and inheritance. The principle of object composition is integral to object-oriented design, and through object composition, objects of any existing class can be used to define new classes. Extending an existing class through inheritance also allows us to use an existing class, but comes with a lot of caveats. Using these mechanisms, we introduce a few basic strategies for enhancing reusability of code.