Chapter 7: Inheritance Abstract Data Types Object Hierarchy Inheritance of Methods Inheritance: implicit passing of information between program components.

Slides:



Advertisements
Similar presentations
Object-Oriented Programming Session 9 Course : T Programming Language Concept Year : February 2011.
Advertisements

Understand and appreciate Object Oriented Programming (OOP) Objects are self-contained modules or subroutines that contain data as well as the functions.
Object Oriented Programming with Java
Inheritance. Many objects have a hierarchical relationship –Examples: zoo, car/vehicle, card game, airline reservation system Inheritance allows software.
Lecture 10: Part 1: OO Issues CS 540 George Mason University.
Abstract Data Types Data abstraction, or abstract data types, is a programming methodology where one defines not only the data structure to be used, but.
Chapter 7 Testing Class Hierarchies. SWE 415 Chapter 7 2 Reading Assignment  John McGregor and David A. Sykes, A Practical Guide to Testing Object-Oriented.
Chapter 12 Support for Object-Oriented Programming.
Chapter 12: Support for Object-Oriented Programming
Chapter 10: Introduction to Inheritance
1 Lecture 3 Inheritance. 2 A class that is inherited is called superclass The class that inherits is called subclass A subclass is a specialized version.
ISBN Chapter 12 Support for Object-Oriented Programming.
OOP in Java Nelson Padua-Perez Chau-Wen Tseng Department of Computer Science University of Maryland, College Park.
1 Software Testing and Quality Assurance Lecture 28 – Testing Class Hierarchies.
1 Chapter 6 Inheritance, Interfaces, and Abstract Classes.
7M701 1 Class Diagram advanced concepts. 7M701 2 Characteristics of Object Oriented Design (OOD) objectData and operations (functions) are combined 
Object-oriented Programming Concepts
OOP in Java Fawzi Emad Chau-Wen Tseng Department of Computer Science University of Maryland, College Park.
ISBN Chapter 12 Support for Object- Oriented Programming.
CS 355 – PROGRAMMING LANGUAGES Dr. X. Copyright © 2012 Addison-Wesley. All rights reserved.1-2 Chapter 12 Topics Introduction Object-Oriented Programming.
Support for Object-Oriented Programming
Chapter 12 Support for Object-Oriented Programming.
Inheritance using Java
Chapter 12: Adding Functionality to Your Classes.
C++ Object Oriented 1. Class and Object The main purpose of C++ programming is to add object orientation to the C programming language and classes are.
Data Structures Using C++ 2E Chapter 3 Pointers and Array-Based Lists.
ISBN Chapter 12 Support for Object-Oriented Programming.
An Object-Oriented Approach to Programming Logic and Design
Introduction to Object Oriented Programming. Object Oriented Programming Technique used to develop programs revolving around the real world entities In.
Chapter 11 Inheritance and Composition. Chapter Objectives Learn about inheritance Learn about subclasses and superclasses Explore how to override the.
Inheritance and Class Hierarchies Ellen Walker CPSC 201 Data Structures Hiram College.
CS 403 – Programming Languages Class 25 November 28, 2000.
The Procedure Abstraction, Part VI: Inheritance in OOLs Comp 412 Copyright 2010, Keith D. Cooper & Linda Torczon, all rights reserved. Students enrolled.
The Procedure Abstraction, Part V: Support for OOLs Comp 412 Copyright 2010, Keith D. Cooper & Linda Torczon, all rights reserved. Students enrolled in.
Chapter 12 Support for Object oriented Programming.
Chapter 12 Support for Object-Oriented Programming.
Chapter 12 Support for Object-Oriented Programming.
Chapter 6 Introduction to Defining Classes. Objectives: Design and implement a simple class from user requirements. Organize a program in terms of a view.
Chapter 10, Slide 1 ABSTRACT DATA TYPES Based on the fundamental concept of ABSTRACTION:  process abstraction  data abstraction Both provide:  information.
Lecture 10 Concepts of Programming Languages Arne Kutzner Hanyang University / Seoul Korea.
Chapter 5 Introduction to Defining Classes
Chapter 12 Support for Object-Oriented Programming.
Object-Oriented Programming Chapter Chapter
(1) ICS 313: Programming Language Theory Chapter 12: Object Oriented Programming.
ISBN Object-Oriented Programming Chapter Chapter
1 Chapter 11 © 1998 by Addison Wesley Longman, Inc The Concept of Abstraction - The concept of abstraction is fundamental in programming - Nearly.
1 CS Programming Languages Class 22 November 14, 2000.
1 Copyright © 1998 by Addison Wesley Longman, Inc. Chapter 10 Abstraction - The concept of abstraction is fundamental in programming - Nearly all programming.
© 2007 Lawrenceville Press Slide 1 Chapter 9 Inheritance  One class is an extension of another.  Allows a class to define a specialized type of an existing.
Classes, Interfaces and Packages
ISBN Chapter 12 Support for Object-Oriented Programming.
Chapter 12: Support for Object- Oriented Programming Lecture # 18.
Chapter 5 Introduction to Defining Classes Fundamentals of Java.
Java Programming: Guided Learning with Early Objects Chapter 9 Inheritance and Polymorphism.
Object-oriented programming (OOP) is a programming paradigm using "objects" – data structures consisting of data fields and methods together with their.
Inheritance Modern object-oriented (OO) programming languages provide 3 capabilities: encapsulation inheritance polymorphism which can improve the design,
The Movement To Objects
Lecture 12 Inheritance.
Support for Object-Oriented Programming
Support for Object-Oriented Programming
Types of Programming Languages
UML Class Diagram: class Rectangle
Java Programming Language
Array-Based Implementations
Parameter Passing Actual vs formal parameters
Support for Object-Oriented Programming
Support for Object-Oriented Programming
Object-Oriented Programming
Lecture 10 Concepts of Programming Languages
C++ Object Oriented 1.
Presentation transcript:

Chapter 7: Inheritance Abstract Data Types Object Hierarchy Inheritance of Methods Inheritance: implicit passing of information between program components. The concept is usually used in the context of complex data objects.

Abstract Data Types Data components Operations to manipulate the data components Implementation of ADT: classes (C++), packages (ADA), objects (Smalltalk) Basic idea: The data components and the programs that implement the operations are hidden from the external world. The object is encapsulated.

Encapsulation Direct encapsulation: Actual storage is maintained in the activation record of subprograms that use the object Indirect encapsulation: Actual storage is maintained only with the specification. Other programs use pointers to the actual storage

Encapsulation Direct encapsulation: runs faster, compilation slow Indirect encapsulation: runs slower, compilation fast

Generic abstract data types Generic abstract data types use templates This is the case when the type of the data components is not fixed in the specification. The operations stay the same no matter what the type is, e.g. a list of integers, a list of characters. Instantiation occurs at compiling time A generic type may be instantiated many times.

Implementation of GADT the generic definition is used as a template specified data types (given in the calling program) are inserted in the definition the definition is compiled Disadvantages: instantiation results in a copy of the entire class (package) definition.

Object hierarchy An object may be a special case of a more general object. Some of the properties are the same - these properties can be inherited

Superclass 1 (parent) Superclass 2 (parent) Subcl 1.1 child Subcl 1. 2 child Subclass2.1 child Subclass2.1 child Derived classes

Multiple Inheritance Superclass 1 (parent) Superclass 2 (parent) Subclass1.1 child Subcl 1. 2 child Subclass2.1 child Subclass2.1 child

Generalization and specialization Down the hierarchy the objects become more specialized, up the hierarchy - more generalized Instantiation – The process of creating instances of a class

Derived classes Derived classes inherit data components and/or methods Further, they can specify their own data components and their own specific methods. The specific parts may have same names as in the parent - they override the definition in the parent class.

Implementation of derived classes Copy-based approach - each instance of a class object has its own data storage containing all data components - specific plus inherited. Direct encapsulation

Implementation of derived classes Delegation-based approach – the object uses the data storage of the base class. Data sharing, Indirect encapsulation

Inheritance of methods Virtual functions class Figure { public: Figure(); virtual void draw(); virtual void erase(); void center(); void set_color(T Color); void position_center(); }; void Figure:: center() { erase(); position_center(); draw(); }

class Box : public Figure { public: Box(); void draw(); void erase(); }; in MAIN: Box a_box; a_box.draw(); // overrides base class a_box.set_color(C); // inherits the method a_box.center(); // makes use of virtual // functions

Implementation of virtual methods A slot in the record defining the class. The constructor fills in the location of the new virtual procedure if there is one. If not, it fills in the location of the virtual procedure from the base class.

Abstract Classes Abstract Classes - can serve only as templates, no data objects can be declared with the name of the class. Specified by NULL virtual functions virtual void TypeName() = 0;