






















Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
lecture otes implemented in both java and C++ on inheritance
Typology: Lecture notes
1 / 30
This page cannot be seen from the preview
Don't miss anything!























©2011, 2014. David W. White & Tyrone A. Edwards School of Computing and Information Technology Faculty of Engineering and Computing University of Technology, Jamaica Email: [email protected], [email protected]
Expected Outcome At the end of this lecture the student should be able to: ●Explain how inheritance facilitates software reuse ●Identify candidates for inheritance relationships during object-oriented analysis ●Represent inheritance relationships in UML ●Represent inheritance relationships in code
Topics to be covered in this lecture: ●Identifying inheritance relationships during object- oriented analysis ●Inheritance relationships in UML ●Inheritance relationships in code
●Inheritance describes a relationship in which child classes derive members from their parent classes ●Inheritance is a key concept of OOP ●The state (attributes) and the behaviours (methods) of the parent class are inherited by the child class ●Can be used to eliminates redundant code ●Promotes software reuse
Inheritance, through software reuse: ●Reduces software development time
●The general members that apply to a set of classes in an inheritance relationship are placed in the parent class called the base ●Hence, the parent is called a generalized class ●Each child class inherits from the parent class and may customize itself to differentiate itself from other child classes, hence it is called a specialization or derived class ●Other synonyms exist for parent and child
●Single inheritance occurs when a child inherits from only one parent ●Multiple Inheritance occurs when a child inherits from more than one parent
●Multiple inheritance can cause problems with ambiguity if the same method name is inherited from more than one parent (which one will the child use?) ●C++ supports single and multiple inheritance ●Java only directly supports single inheritance but interfaces can simulate multiple inheritance
Private ●The members of the parent class are inherited but cannot be accessed by the child class Public ●The members of the parent class are inherited and can be accessed by the child class and other classes Protected ●The members of the parent class are inherited and can only be accessed by the child its descendants
●When conducting Object-Oriented Analysis (OOA), terms such as “is a” hint at a possible inheritance relationship ●For this reason, inheritance is also called an “is-a” relationship or a generalization
If a set of classes are very similar, containing common attributes and/or methods: ●Define a parent class ●Place the common attributes and methods in the parent class ●Place only the attributes and methods that make each child class unique in their respective class
Example: A dialog box has a title, x and y coordinates, height, and width, and some message text. It has click close, click maximize, click minimize and click ok operations. A modal form has a title, warning level and some message text. It has click ok and beep operations. ●Perform an OOA on the above to identify the classes, attributes, methods and relationship
Class: window ●Attributes: title, and message text ●Method: clickOk
Parent class: window Child classes: modal form, dialog box ●Classes modal form and dialog box inherit the title and message text attributes and the clickOk method from the window class.