Software Engineering I Notes for Sept. 9, 2013 Methods, Operations, & Polymorphism Polymorphism - property of OO SW where an abstract operation may be performed in many different ways. Methods are procedural abstractions used to implement the behavior of a class Operations (in the context of SW Eng) are higher level abstractions than methods and are independent of code. Example: Inheritance from an Account Class +--------------+ | Account | +--------------+ |CalcInterest()| +--------------+ ^ / \ -+- | +-----------+-------------------+ | | | +-----+--------+ ++-------------+ +------+--------+ |SavingsAcct | |CheckingAcct | |MortgageAcct | +--------------+ +--------------+ +---------------+ |CalcInterest()| |CalcInterest()| |CalcInterest() | +--------------+ +--------------+ +---------------+ Inheritance Hierarchy Superclass - has features common to many classes to avoid duplication Subclass - allows for specialization to divide complex functionality Example: common features to accounts such as open, close, deposit Specialized features -Mortgage Account may need special interest function Superclasses relationship to subclass is called generalization or parent Subclass relationship to superclass is called specialization or child Inheritance is the implicit possession by a subclass of all features defined in the superclasses (parent and ancestor classes) including variables and methods. How does this work in Java? Rules -ambiguous names often give poor generalizations -subclasses should be distinctive -all inherited features should make sense Begin discussion of effect on inheritance hierarchies on polymorphism and variable declarations.