C++ Classes C++ Interlude 1.

Slides:



Advertisements
Similar presentations
Has-a Relationships A pen “has a” or “contains a” ball.
Advertisements

Derived Classes. C++ 2 Outline  Definition  Virtual functions  Virtual base classes  Abstract classes. Pure virtual functions.
Week 8 Recap CSE 115 Spring Composite Revisited Once we create a composite object, it can itself refer to composites. Once we create a composite.
Objectives Introduction to Inheritance and Composition (Subclasses and SuperClasses) Overriding (and extending), and inheriting methods and constructors.
© 2006 Pearson Addison-Wesley. All rights reserved9 A-1 Chapter 9 Advanced Java Topics (inheritance review + Java generics)
ITEC200 – Week03 Inheritance and Class Hierarchies.
1 Lab Session-1 CSIT221 Fall 2002 b Refresher slides b Practice Problem b Lab Exercise (Demo Required)
CSE 115 Week 10 March , Announcements March 21 – Lab 7 Q & A in lecture March 21 – Lab 7 Q & A in lecture March 26 – Exam 7 March 26 – Exam.
C++ data types. Structs vs. Classes C++ Classes.
OOP Etgar 2008 – Recitation 71 Object Oriented Programming Etgar 2008 Recitation 7.
C++ Interlude 2 Pointers, Polymorphism, and Memory Allocation
CSE 250: Data Structures Week 3 January 28 – February 1, 2008.
8.1 Classes & Inheritance Inheritance Objects are created to model ‘things’ Sometimes, ‘things’ may be different, but still have many attributes.
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.
Virtual Functions Fall 2008 Dr. David A. Gaitros
Data Structures Using C++1 Chapter 2 Object-Oriented Design (OOD) and C++
Data Structures Using C++1 Chapter 2 Object-Oriented Design (OOD) and C++
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.
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Taken from slides of Starting Out with C++ Early Objects Seventh Edition.
Chapter 15 – Inheritance, Virtual Functions, and Polymorphism
1 Chapter 14 Object-Oriented Software Development Dale/Weems/Headington.
Inheritance in the Java programming language J. W. Rider.
ADTs and C++ Classes Classes and Members Constructors The header file and the implementation file Classes and Parameters Operator Overloading.
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley. Ver Chapter 8: Class Relationships Data Abstraction & Problem Solving.
CSE 341, S. Tanimoto Java brief review - 1 Java Brief Review Java’s strengths Object-oriented terminology Inheritance Interfaces An example with inheritance.
Chapter 10: Introduction to Inheritance. Objectives Learn about the concept of inheritance Extend classes Override superclass methods Call constructors.
Advanced C++ Topics Chapter 8. CS 308 2Chapter 8 -- Advanced C++ Topics This chapter describes techniques that make collections of reusable software components.
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.
Department of Computer Science Data Structures Using C++ 2E Chapter 2 Object-Oriented Design (OOD) and C++  Learn about inheritance  Learn about derived.
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.
C++ Classes C++ Interlude 1 Data Structures and Problem Solving with C++: Walls and Mirrors, Carrano and Henry, © 2013.
Object orientation and Packaging in Java Object Orientation and Packaging Introduction: After completing this chapter, you will be able to identify.
Inheritance Chapter 11 in Gaddis. Is a relationships in ‘real’ life Exist when one object is a specialized version of another one –Examples An english.
Inheritance in C++ Bryce Boe 2012/08/28 CS32, Summer 2012 B.
Classes Classes are a major feature of C++. They support – – Abstraction – Data hiding – Encapsulation – Modularity – Re-use through inheritance.
Georgia Institute of Technology Comic Strip Analysis and Design Inheritance, Abstract Classes, and Polymorphism part 2 Barb Ericson Georgia Institute of.
Interlude 1 C++ Classes CS Data Structures Mehmet H Gunes Modified from authors’ slides.
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.
Introduction to Classes and Objects CS-2303, C-Term C++ Program Structure Typical C++ Programs consist of:– main –A function main –One or more classes.
Java Programming Fifth Edition Chapter 9 Introduction to Inheritance.
Inheritance Modern object-oriented (OO) programming languages provide 3 capabilities: encapsulation inheritance polymorphism which can improve the design,
Classes and Inheritance
© 2017 Pearson Education, Hoboken, NJ. All rights reserved
Inheritance and Polymorphism
One class is an extension of another.
Pointers, Polymorphism, and Memory Allocation
Class A { public : Int x; A()
Object-Oriented Programming
CS212: Object Oriented Analysis and Design
Inheritance AKEEL AHMED.
Advanced C++ Topics Chapter 8.
C++ Classes C++ Interlude 1
Interfaces.
One class is an extension of another.
Java Programming Language
Abstract Classes AKEEL AHMED.
C++ Interlude 1 C++ Classes
Polymorphism Polymorphism
Array-Based Implementations
9: POLYMORPHISM Programming Technique II (SCSJ1023) Jumail Bin Taliba
Fundaments of Game Design
Chapter 8: Class Relationships
Inheritance and Polymorphism
Chapter 11 Class Inheritance
ENERGY 211 / CME 211 Lecture 22 November 10, 2008.
C++ data types.
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.
Presentation transcript:

C++ Classes C++ Interlude 1

A Problem to Solve Consider a video game where a character carries three types of boxes Plain box Toy box Magic box Plain box design Get and Set public methods

A Problem to Solve LISTING C1-1 The header file for the class PlainBox

A Problem to Solve LISTING C1-1 The header file for the class PlainBox

A Problem to Solve Elements of the class Private data fields Constructors, destructors Methods Use of #ifndef , #define , and #endif preprocessor directives Use of initializers Use of typedef Inheritance

A Problem to Solve LISTING C1-2 Implementation file for the PlainBox class

A Problem to Solve LISTING C1-3 Template header file for the PlainBox class

A Problem to Solve LISTING C1-3 Template header file for the PlainBox class

A Problem to Solve LISTING C1-4 Implementation file for the PlainBox template class

A Problem to Solve LISTING C1-4 Implementation file for the PlainBox template class

Base Classes and Derived Classes Use PlainBox as a base class , or superclass The ToyBox class is the derived class , or subclass , of the PlainBox Derived class inherits All the members of its base class, (Except the constructors and destructor)

Base Classes and Derived Classes LISTING C1-5 Template header file for the class ToyBox

Base Classes and Derived Classes LISTING C1-6 Implementation file for the class ToyBox

Overriding Base-Class Methods You can add as many new members to derived class as desired You can redefine inherited methods Called overriding a base-class method. A method overrides a base-class method when The two methods have the same name and parameter declarations

Overriding Base-Class Methods LISTING C1-7 Header file for the class MagicBox

Overriding Base-Class Methods LISTING C1-8 Implementation file for the class MagicBox

Virtual Methods, Abstract Classes Using keyword virtual in front of the prototype Tells the C++ compiler that the code this method executes is determined at runtime Pure virtual method Virtual method that has no implementation Abstract class Has at least one pure virtual method

Virtual Methods, Abstract Classes LISTING C1-9 An abstract class that is an interface for the ADT box

End Interlude 1