Lec5_Inheritance - ITI 1121. Introduction to Computing II *...

Info iconThis preview shows pages 1–10. Sign up to view the full content.

View Full Document Right Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: ITI 1121. Introduction to Computing II * Marcel Turcotte School of Information Technology and Engineering Version of January 21, 2010 Abstract • Inheritance – Introduction – Generalization/specialization * These lecture notes are meant to be looked at on a computer screen. Do not print them unless it is necessary. Summary We have seen that object-oriented programming (OOP) helps organizing and maintaining large software systems. The data, and the methods that act upon the data, are encapsulated into a single entity called the object. The instance variables define the properties or state of an object. In particular, we have seen that OOP provides mechanisms to control the visibility of the methods and the variables. The methods and variables that are public define the interface of the object. Having the interface clearly defined allows the implementers and the users of the class to work independently; the creator can change the implementation of the class, as long as it does not affect the interface, and the programs developed by the users will continue to work. As a general principle, in CS II, all the instance variables should be declared private. If the value of a variable needs to be accessed (read or mutated) from outside the class, then the interface of the object will include setter and getter methods. This principle will allow us to maintain the integrity of the objects. The class specifies the content of the objects but it also exists during the execution of a program. Each object knows the class from which it was instantiated from (is an instance of). No matter how many instances there are, 0, 1 or n , there is only one copy of the class. Class variables and methods are shared by all instances of a class. ⇒ In today’s lecture, we look at other important features of object-oriented programming that help organizing and maintaining large software systems: inheritance and polymorphism . Inheritance OO languages, in general, also offer other tools to structure large systems. Inheritance is one of them. Inheritance allows to organize the classes hierarchically. Inheritance favors code reuse ! Inheritance The class immediately above is called the superclass or parent class while the class immediately below is called the subclass , child class or derived class . Bird Pigeon is a In this example, Bird is the superclass of Pigeon , i.e. Pigeon “is a” subclass of Bird . Inheritance Bird Pigeon is a In Java, the “is a” relationship is expressed using the reserved keyword extends , as follows: public class Pigeon extends Bird { ... } Inheritance Bird Pigeon is a In UML, the “is a” relationship is expressed using a continuous line connecting the child to its parent, and an open triangle pointing towards the parent. Inheritance In Java, the classes are organized into a single hierarchy, with the most general class, called Object , being at the top (or root ) of the tree. Object #clone(): Object +equals(Object:obj): boolean +getClass(): Class...
View Full Document

This note was uploaded on 01/06/2011 for the course ITI 1121 taught by Professor Samaan during the Spring '10 term at University of Ottawa.

Page1 / 90

Lec5_Inheritance - ITI 1121. Introduction to Computing II *...

This preview shows document pages 1 - 10. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online