COP 3330 Object-oriented Programming in C++

Slides:



Advertisements
Similar presentations
Chapter 14 Inheritance Pages ( ) 1. Inheritance: ☼ Inheritance and composition are meaningful ways to relate two or more classes. ☼ Inheritance.
Advertisements

Constructor. 2 constructor The main use of constructors is to initialize objects. A constructor is a special member function, whose name is same as class.
Contents o Introduction o Characteristics of Constructor. o Types of constructor. - Default Constructor - Parameterized Constructor - Copy Constructor.
CS-1030 Dr. Mark L. Hornick 1 Constructors Copy Constructors.
Object Oriented Programming COP3330 / CGS5409.  C++ Automatics ◦ Copy constructor () ◦ Assignment operator =  Shallow copy vs. Deep copy  DMA Review.
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.
OOP Languages: Java vs C++
Association & Aggregation Lecture-9. Vehicle Car Tyre Engine Bus Passenger.
Starting Chapter 4 Starting. 1 Course Outline* Covered in first half until Dr. Li takes over. JAVA and OO: Review what is Object Oriented Programming.
Programming Languages and Paradigms Object-Oriented Programming.
Classes Mark Hennessy Dept. Computer Science NUI Maynooth C++ Workshop 18 th – 22 nd Spetember 2006.
Chapter 15 – Inheritance, Virtual Functions, and Polymorphism
Object Oriented Programming Philosophy. Part 1 -- Basic Understanding & Encapsulation.
Java Class Syntax CSIS 3701: Advanced Object Oriented Programming.
Programming Languages and Paradigms Object-Oriented Programming (Part II)
CS212: Object Oriented Analysis and Design Lecture 7: Arrays, Pointers and Dynamic Memory Allocation.
Copy Constructors Fall 2008 Dr. David A. Gaitros
 Classes in c++ Presentation Topic  A collection of objects with same properties and functions is known as class. A class is used to define the characteristics.
Aggregation/Composition Programming in C++ Fall 2008 Dr. David A. Gaitros
Object Oriented Programming COP3330 / CGS5409.  Inheritance  Assignment 5.
OOP in C++ CS 124. Program Structure C++ Program: collection of files Source (.cpp) files be compiled separately to be linked into an executable Files.
C++ Lecture 5 Monday, 18 July Chapter 7 Classes, continued l const objects and const member functions l Composition: objects as members of classes.
1 Liang, Introduction to C++ Programming, (c) 2007 Pearson Education, Inc. All rights reserved X 1 Chapter 10 More on Objects and Classes.
Liang, Introduction to C++ Programming, (c) 2007 Pearson Education, Inc. All rights reserved X 1 Chapter 10 More on Objects and Classes.
Copyright © 2009 – Curt Hill Standard Template Library An Introduction.
1 CSC241: Object Oriented Programming Lecture No 17.
Object Oriented Programming COP3330 / CGS5409.  Aggregation / Composition  Dynamic Memory Allocation.
1 Introduction to Object Oriented Programming Chapter 10.
Classes: A Deeper Look D & D Chapter 9 Instructor - Andrew S. O’Fallon CptS 122 Washington State University.
Learners Support Publications Constructors and Destructors.
Constructors and Destructors
Class Relationships in C++
Inheritance CMSC 202, Version 4/02.
Aggregation / Composition
Andy Wang Object Oriented Programming in C++ COP 3330
Chapter 9 More on Objects and Classes
Inheritance, Polymorphism, and Virtual Functions
Object Oriented Programming COP3330 / CGS5409
Aggregation / Composition
Constructor & Destructor
Three Minute Timer Two Minute Timer One Minute Timer
Class: Special Topics Copy Constructors Static members Friends this
Week 4 Object-Oriented Programming (1): Inheritance
More about OOP and ADTs Classes
This pointer, Dynamic memory allocation, Constructors and Destructor
group work #hifiTeam
Automatics, Copy Constructor, and Assignment Operator
More on Classes Classes may have constructors which are called when objects are created and destructors which are called when objects are destroyed. Classes.
OOP Paradigms There are four main aspects of Object-Orientated Programming Inheritance Polymorphism Abstraction Encapsulation We’ve seen Encapsulation.
CSCI 1260 – Lecture 2: Instantiation, Aggregation, and Composition
MSIS 670 Object-Oriented Software Engineering
Lecture 22 Inheritance Richard Gesick.
Chapter 4 (part 2).
Andy Wang Object Oriented Programming in C++ COP 3330
Inheritance, Polymorphism, and Virtual Functions
More about OOP and ADTs Classes
Constructors and Destructors
The Destructor and the Assignment Operator
Constructors, GUI’s(Using Swing) and ActionListner
Object Oriented Programming Review
COP 3330 Object-oriented Programming in C++
Constructors/Destructors Functions Revisited
NAME 436.
Andy Wang Object Oriented Programming in C++ COP 3330
CMSC202 Computer Science II for Majors Lecture 10 and 11 – Inheritance
COP 3330 Object-oriented Programming in C++
COP 3330 Object-oriented Programming in C++
Class: Special Topics 2 For classes using memory allocation
Constructors & Destructors
Object Oriented Programming
Presentation transcript:

COP 3330 Object-oriented Programming in C++ Composition Spring 2019

Object as Class Members Aggregation is a relationship between objects Embed an object (or a pointer) of one class type as member data of another class type Composition refers to a stronger form of aggregation Embedded objects would typically not exist independent of the container object Is also known as the “has a” relationship Engine object inside a Car object as member data 52 Card objects as member data of class Deck Promotes the idea of tool building Objects of a class can be used as components inside other classes

Let’s Build a Timer Hour Display Minute Display Second Display

Timer & Display The user of Timer is the main program The user of Display objects is Timer object Timer object will call Display functions through its member data objects (hours, minutes, seconds) Timer Class Display hours Display minutes Display seconds 0..23 0..59 0..59

Display Class

Timer Class Three Display components

Constructors/Destructors for Embedded Objects When an object (Timer) is created, its constructor runs and also invokes the constructors of its embedded objects (Display) If nothing is done, it will invoke the default constructor Use initialization lists to invoke a constructor with parameters for embedded objects When an object (Timer) is destroyed, its destructor runs and also invokes the destructors of its embedded objects (Display) The life span of a Timer object is longer than, and fully covers, those of Display objects

Constructors for Embedded Objects Normal creation of Display objects Creation of Display objects in the Timer Constructor Display hours(24); Display minutes(60); Display seconds(60); Initialization cannot be performed in the class declaration Need to use an initialization list Display has no default constructor Timer::Timer() : hours(24), minutes(60), Seconds(60) { }

Questions