Jim Fawcett CSE687 – Object Oriented Design Spring 2014

Slides:



Advertisements
Similar presentations
Chapter 1 OO using C++. Abstract Data Types Before we begin we should know how to accomplish the goal of the program We should know all the input and.
Advertisements

CSE 1302 Lecture 8 Inheritance Richard Gesick Figures from Deitel, “Visual C#”, Pearson.
Classes and Object- Oriented... tMyn1 Classes and Object-Oriented Programming The essence of object-oriented programming is that you write programs in.
OOP in Java Fawzi Emad Chau-Wen Tseng Department of Computer Science University of Maryland, College Park.
© 2006 Pearson Addison-Wesley. All rights reserved9 A-1 Chapter 9 Advanced Java Topics CS102 Sections 51 and 52 Marc Smith and Jim Ten Eyck Spring 2007.
PolymorphismCS-2303, C-Term Polymorphism Hugh C. Lauer Adjunct Professor (Slides include materials from The C Programming Language, 2 nd edition,
Chapter 7 - Generalization/Specialization and Inheritance1 Chapter 7 Generalization/Specialization and Inheritance.
Shallow Versus Deep Copy and Pointers Shallow copy: when two or more pointers of the same types point to the same memory – They point to the same data.
Inheritance in C++ CS-1030 Dr. Mark L. Hornick.
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Taken from slides of Starting Out with C++ Early Objects Seventh Edition.
Dr. Ahmad R. Hadaegh A.R. Hadaegh California State University San Marcos (CSUSM) Page 1 Virtual Functions Polymorphism Abstract base classes.
Chapter 15 – Inheritance, Virtual Functions, and Polymorphism
Polymorphism. Introduction ‘one name multiple forms’ Implemented using overloaded functions and operators Early binding or static binding or static linking.
“is a”  Define a new class DerivedClass which extends BaseClass class BaseClass { // class contents } class DerivedClass : BaseClass { // class.
Lecture 8 Inheritance Richard Gesick. 2 OBJECTIVES How inheritance promotes software reusability. The concepts of base classes and derived classes. To.
CISC6795: Spring Object-Oriented Programming: Polymorphism.
Lecture 9 Polymorphism Richard Gesick.
CSE 425: Object-Oriented Programming I Object-Oriented Programming A design method as well as a programming paradigm –For example, CRC cards, noun-verb.
CS200 Algorithms and Data StructuresColorado State University Part 4. Advanced Java Topics Instructor: Sangmi Pallickara
Copyright 2006 Oxford Consulting, Ltd1 February Polymorphism Polymorphism Polymorphism is a major strength of an object centered paradigm Same.
What Is Inheritance? Provides a way to create a new class from an existing class New class can replace or extend functionality of existing class Can be.
Summing Up Object Oriented Design. Four Major Components: Abstraction modeling real-life entities by essential information only Encapsulation clustering.
Object-Oriented Programming Chapter Chapter
(1) ICS 313: Programming Language Theory Chapter 12: Object Oriented Programming.
OOPs Object oriented programming. Abstract data types  Representationof type and operations in a single unit  Available for other units to create variables.
Class Relationships And Reuse Interlude 4 Data Structures and Problem Solving with C++: Walls and Mirrors, Frank Carrano, © 2012.
CS-1030 Dr. Mark L. Hornick 1 Basic C++ State the difference between a function/class declaration and a function/class definition. Explain the purpose.
ISBN Object-Oriented Programming Chapter Chapter
Recap Introduction to Inheritance Inheritance in C++ IS-A Relationship Polymorphism in Inheritance Classes in Inheritance Visibility Rules Constructor.
Polymorphism and Virtual Functions One name many shapes behaviour Unit - 07.
C++ General Characteristics: - Mixed typing system - Constructors and destructors - Elaborate access controls to class entities.
1 Inheritance One of the goals of object oriented programming is code reuse. Inheritance is one mechanism for accomplishing code reuse. It allows us to.
Object-Oriented Programming Review 1. Object-Oriented Programming Object-Oriented Programming languages vary but generally all support the following features:
Java Programming: Guided Learning with Early Objects Chapter 9 Inheritance and Polymorphism.
Inheritance Modern object-oriented (OO) programming languages provide 3 capabilities: encapsulation inheritance polymorphism which can improve the design,
Copyright © Jim Fawcett Spring 2017
Object-Oriented Programming Concepts
Chapter 6 - Hierarchy CSE687 – Object Oriented Design Class Notes
Polymorphism, Interfaces & Operator Overloading
Jim Fawcett CSE681 – SW Modeling & Analysis Fall 2014
Classes and Inheritance
Inheritance and Polymorphism
CSE687 - Object Oriented Design class notes Survey of the C++ Programming Language Jim Fawcett Spring 2004.
Class A { public : Int x; A()
Object-Oriented Programming
Polymorphism.
Inheritance Modern object-oriented (OO) programming languages provide 3 capabilities: encapsulation inheritance polymorphism which can improve the design,
Types of Programming Languages
Object Oriented Programming
Lecture 23 Polymorphism Richard Gesick.
Lecture 22 Inheritance Richard Gesick.
Virtual Functions Department of CSE, BUET Chapter 10.
Advanced Java Topics Chapter 9
Inheritance, Polymorphism, and Virtual Functions
Polymorphism Polymorphism
9: POLYMORPHISM Programming Technique II (SCSJ1023) Jumail Bin Taliba
Polymorphism Professor Hugh C. Lauer CS-2303, System Programming Concepts (Slides include materials from The C Programming Language, 2nd edition, by Kernighan.
Virtual Functions Polymorphism is supported by C++ both at compile time and at run time. Compile-time polymorphism is achieved by overloading functions.
Object-Oriented Programming: Inheritance and Polymorphism
Fundaments of Game Design
VIRTUAL FUNCTIONS RITIKA SHARMA.
CIS 199 Final Review.
Lecture 10 Concepts of Programming Languages
Chapter 11 Class Inheritance
Jim Fawcett CSE681 – SW Modeling & Analysis Fall 2018
ENERGY 211 / CME 211 Lecture 22 November 10, 2008.
The Object Paradigm Classes – Templates for creating objects
Static Binding Static binding chooses the function in the class of the base class pointer, ignoring any versions in the class of the object actually.
Computer Science II for Majors
Jim Fawcett CSE687 – Object Oriented Design Spring 2015
Presentation transcript:

Jim Fawcett CSE687 – Object Oriented Design Spring 2014 Using Inheritance Jim Fawcett CSE687 – Object Oriented Design Spring 2014

Topics: Using Inheritance Protocol Classes Hooks Mixin Classes Sharing common code Reusing Implementation

Liskov Substitutability (LS) Public inheritance is a contract for substitutability. Any base class reference or pointer may be bound to an instance of any class derived from that base. The compiler will ensure that derived public interfaces support LS syntactically: Derived classes inherit all of the inheritable methods of the base class and so can receive its messages. It is up to you to ensure semantic LS. Your class must be a semantic specialization of the base.

Protocol Classes A protocol class (C++ interface) provides a language for clients to use when interacting with any of its derived class instances. It has: No data No declared constructors A virtual destructor A set of pure virtual functions that define the hierarchy’s language. All classes are derived from the protocol base class using public inheritance.

Protocol Example

Hooks A hook is a base class that supports modification of a library’s behavior by applications designed to use the library, without modifying any of the library’s code. The Hook class provides a protocol for application designers to use and a set of virtual methods that are overridden to provide required application behavior. One very common usage provides a way for applications to respond to events that occur within the library.

Hook Example The Hook Library code invokes the hook when specific events occur. What’s actually called

Mixins A mixin class provides a specialized set of behaviors intended to be used through multiple inheritance with other classes. Mixins can be used to provide reference counting, locking, memory management, and other specialized behaviors as services to any class that needs them.

Mixin Example

Share Common Code A base class may provide default implementations of some or all of the base class protocol. These, then, are shared by all derived classes that do not override the defaults. When using concrete base classes, however, you need to be careful that you support reasonable semantics: Disallow assignment of derived instances to base instances or derived instances of one type to an instance of another type through base pointers or references. You can make the base class abstract by including a pure virtual function and make the base assignment private. Provide assignment operators for each of the derived classes.

Reusing Implementation C++ supports reuse of implementation with public, private, and protected inheritance. You should prefer composition unless: You need access to protected data from the base class, or: You want to support polymorphic operations in member functions of the derived class, perhaps to bind to any derived object passed to a member function by base reference or pointer without knowing the concrete class of the object.

End of Presentation