上游充通大兽 SHANGHAI JIAO TONG UNIVERSITY (2)Inheritance Inheritance is used to achieve two different goals Description of Taxonomies Implementation Specification Identification of taxonomies Used during requirements analysis. Activity:identify application domain objects that are hierarchically related Goal:make the analysis model more understandable Implementation specification Used during object design ·Activity: Goal:increase reusability,enhance modifiability and extensibility Inheritance is found either by specialization or generalization Software Engineering
Software Engineering (2) Inheritance Inheritance is used to achieve two different goals • Description of Taxonomies • Implementation Specification Identification of taxonomies • Used during requirements analysis. • Activity: identify application domain objects that are hierarchically related • Goal: make the analysis model more understandable Implementation specification • Used during object design • Activity: • Goal: increase reusability, enhance modifiability and extensibility Inheritance is found either by specialization or generalization
上游究通大学 SHANGHAI JIAO TONG UNIVERSITY Inheritance is used during analysis and object design Inheritance Object Design Analysis activity Taxonomy Inheritance for Reuse Inheritance detected Inheritance detected Specification Implementation by specialization by generalization Inheritance Inheritance Software Engineering
Software Engineering Inheritance is used during analysis and object design Inheritance Specification Inheritance Implementation Inheritance Inheritance for Reuse Taxonomy Inheritance detected by generalization Inheritance detected by specialization Analysis activity Object Design
上游文通大警 SHANGHAI JIAO TONG UNIVERSITY Taxonomy Example Mammal Tiger Wolf Wale Software Engineering
Software Engineering Taxonomy Example Mammal Tiger Wolf Wale
上游充通大学 Specification Inheritance SHANGHAI JIAO TONG UNIVERSITY vs Implementation Inheritance Specification inheritance Also called subtyping Inherit from an abstract class with all operations specified,but not yet implemented Implementation inheritance Also called class inheritance Goal:Extend an applications'functionality by reusing functionality in parent class Inherit from an existing class with some or all operations already implemented Software Engineering
Software Engineering Specification Inheritance vs Implementation Inheritance Specification inheritance • Also called subtyping • Inherit from an abstract class with all operations specified, but not yet implemented Implementation inheritance • Also called class inheritance • Goal: Extend an applications’ functionality by reusing functionality in parent class • Inherit from an existing class with some or all operations already implemented
上游文通大警 Implementation Inheritance SHANGHAI JIAO TONG UNIVERSITY A very similar class is already implemented that does almost the same as the desired class implementation. List Example:I have a List class,I need a Stack class.How about Add() subclassing the Stack class Remove() from the List class and “Already providing three methods, mplemented” Push()and Pop(),Top()? Stack Push() Pop() Top() g Problem with implementation inheritance: Some of the inherited operations might exhibit unwanted behavior. What hannens if the Stack user calls Remove()instead of Pop()? An elephant becomes a car! Software Engineering
Software Engineering Problem with implementation inheritance: Some of the inherited operations might exhibit unwanted behavior. What happens if the Stack user calls Remove() instead of Pop()? Example: I have a List class, I need a Stack class. How about subclassing the Stack class from the List class and providing three methods, Push() and Pop(), Top()? Add() Remove() List Push() Pop() Stack Top() “Already implemented” Implementation Inheritance A very similar class is already implemented that does almost the same as the desired class implementation. An elephant becomes a car!