ENERGY 211 / CME 211 Lecture 22 November 10, 2008.

Slides:



Advertisements
Similar presentations
PHP functions What are Functions? A function structure:
Advertisements

OOP Abstraction Classes Class Members: Properties & Methods Instance (object) Encapsulation Interfaces Inheritance Composition Polymorphism Using Inheritance.
Contents o Introduction o Characteristics of Constructor. o Types of constructor. - Default Constructor - Parameterized Constructor - Copy Constructor.
Inheritance. Many objects have a hierarchical relationship –Examples: zoo, car/vehicle, card game, airline reservation system Inheritance allows software.
Derived Classes. C++ 2 Outline  Definition  Virtual functions  Virtual base classes  Abstract classes. Pure virtual functions.
C++ Classes & Data Abstraction
Objectives Introduction to Inheritance and Composition (Subclasses and SuperClasses) Overriding (and extending), and inheriting methods and constructors.
1 Software Testing and Quality Assurance Lecture 28 – Testing Class Hierarchies.
Chapter 15 What is 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. Types of Inheritance Implementation inheritance means that a type derives from a base type, taking all the base type’s member fields and.
1 Classes- Inheritance Multiple Inheritance It is possible to derive a new class from more than one base class. This is called Multiple Inheritance. Under.
Chapter 15 – Inheritance, Virtual Functions, and Polymorphism
Overview of Previous Lesson(s) Over View  OOP  A class is a data type that you define to suit customized application requirements.  A class can be.
Lecture 8 Inheritance Richard Gesick. 2 OBJECTIVES How inheritance promotes software reusability. The concepts of base classes and derived classes. To.
Inheritance. Recall the plant that we defined earlier… class Plant { public: Plant( double theHeight ) : hasLeaves( true ), height (theHeight) { } Plant(
Inheritance Joe Meehean. Object Oriented Programming Objects state (data) behavior (methods) identity (allocation of memory) Class objects definition.
CS212: Object Oriented Analysis and Design Lecture 15: Inheritance in C++ -II.
Copyright 2006 Oxford Consulting, Ltd1 February Polymorphism Polymorphism Polymorphism is a major strength of an object centered paradigm Same.
C# Classes and Inheritance CNS 3260 C#.NET Software Development.
Class and Structure. 2 Structure Declare using the keyword struct purpose is to group data Default visibility mode is public A struct doesn't have a constructor.
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.
CS212: Object Oriented Analysis and Design Lecture 16: Runtime Polymorphism.
JAVA INTRODUCTION. What is Java? 1. Java is a Pure Object – Oriented language 2. Java is developing by existing languages like C and C++. How Java Differs.
© 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.
Access Specifier. Anything declared public can be accessed from anywhere. Anything declared private cannot be seen outside of its class. When a member.
Inheritance in C++ Bryce Boe 2012/08/28 CS32, Summer 2012 B.
C++ General Characteristics: - Mixed typing system - Constructors and destructors - Elaborate access controls to class entities.
Mr H Kandjimi 2016/01/03Mr Kandjimi1 Week 3 –Modularity in C++
Object-Oriented Programming Review 1. Object-Oriented Programming Object-Oriented Programming languages vary but generally all support the following features:
Abstract classes only used as base class from which other classes can be inherit cannot be used to instantiate any objects are incomplete Classes that.
Chapter 11: Abstract Data Types Lecture # 17. Chapter 11 Topics The Concept of Abstraction Advantages of Abstract Data Types Design Issues for Abstract.
Constructors and Destructors
Classes and Inheritance
© 2017 Pearson Education, Hoboken, NJ. All rights reserved
2.7 Inheritance Types of inheritance
Final and Abstract Classes
One class is an extension of another.
Testing Object-Oriented Software Concepts and Definitions
Object-Oriented Programming & Design Lecture 18 Martin van Bommel
Object-Oriented Programming
Polymorphism.
Inheritance Modern object-oriented (OO) programming languages provide 3 capabilities: encapsulation inheritance polymorphism which can improve the design,
Inheritance Often, software encapsulates multiple concepts for which some attributes/behaviors overlap E.g. A computer (role-playing) game has: Monsters:
C++ Classes C++ Interlude 1.
One class is an extension of another.
Interface.
Lecture 22 Inheritance Richard Gesick.
Abstract Classes AKEEL AHMED.
Inheritance Dr. Bhargavi Goswami Department of Computer Science
Interfaces.
Advanced Java Programming
More Object-Oriented Programming
Polymorphism Polymorphism
Constructors and Destructors
Polymorphism Professor Hugh C. Lauer CS-2303, System Programming Concepts (Slides include materials from The C Programming Language, 2nd edition, by Kernighan.
Object-Oriented Programming in PHP
CISC/CMPE320 - Prof. McLeod
Fundaments of Game Design
Chapter 11: Inheritance and Composition
Chapter 8: Class Relationships
Today’s Objectives 10-Jul-2006 Announcements Quiz #3
NAME 436.
Final and Abstract Classes
ENERGY 211 / CME 211 Lecture 30 December 5, 2008.
ENERGY 211 / CME 211 Lecture 17 October 29, 2008.
Jim Fawcett CSE687 – Object Oriented Design Spring 2014
C++ Polymorphism Reference and pointer implicit type casting
C++ Object Oriented 1.
SPL – PS4 C++ Advanced OOP.
Presentation transcript:

ENERGY 211 / CME 211 Lecture 22 November 10, 2008

Specializing Classes Often, classes have similar operations or data Maintaining such classes separately is wasteful Can put common functionality in a base class, and put class-specific features in derived classes that inherit from the base class Then, further extensions in new directions can easily be made

Derived Classes The declaration class derived-class : access-spec base-class { access-specifier1:decl-list1 access-specifier2:decl-list2 … }; allows derived-class to inherit from base-class, according to access-spec Do not re-declare inherited members unless you intend to override them

Inheritance Normally, inheritance is public public members of the base class are available in the derived class private members of the base class are not available to the derived class A public or protected member variable cannot be declared in both A public/protected member function can be, but don't do it unless base function is virtual (coming up)

Protected members protected members are available only to derived classes, and are considered protected in the derived class as well Using the protected specifier is the way to allow inheritance for members that would normally be private if declared in the derived class Use private for members that are used only in their own class

Constructors Constructors for derived classes can be implemented in the same way as for base classes They first call the default constructor for the base class (that has no arguments) Can select a different base constructor Form: derv::derv(derv-args): base(base-args)compound-stmt where derv is the derived class and base is the base class

Virtual Functions To have member function in derived class override that of base class, declare base class function virtual: virtual type name(args); Always make base destructor virtual, or derived destructor may not be called! Add = 0; to end of virtual declaration to make function pure virtual; this makes base class an abstract class (can't create objects)

Next Time All about templates Template functions Template classes Specializing Templates