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.

Slides:



Advertisements
Similar presentations
Lecture 10: Part 1: OO Issues CS 540 George Mason University.
Advertisements

Java Inheritance. What is inherited A subclass inherits variables and methods from its superclass and all of its ancestors. The subclass can use these.
Chapter 1 Object Oriented Programming. OOP revolves around the concept of an objects. Objects are crated using the class definition. Programming techniques.
. Virtual Classes & Polymorphism. Example (revisited) u We want to implement a graphics system u We plan to have lists of shape. Each shape should be.
ITEC200 – Week03 Inheritance and Class Hierarchies.
Polymorphism From now on we will use g++!. Example (revisited) Goal: Graphics package Handle drawing of different shapes Maintain list of shapes.
Rossella Lau Lecture 8, DCO10105, Semester B, DCO10105 Object-Oriented Programming and Design  Lecture 8: Polymorphism & C++ pointer  Inheritance.
16/22/2015 2:54 PM6/22/2015 2:54 PM6/22/2015 2:54 PMObject-Oriented Development Concept originated with simulating objects and their interactions. Adapted.
C++ Interlude 2 Pointers, Polymorphism, and Memory Allocation
Inheritance, Polymorphism, and Virtual Functions
Inheritance Modern object-oriented (OO) programming languages provide 3 capabilities: encapsulation - a language mechanism for restricting access to some.
Virtual Functions Junaed Sattar November 10, 2008 Lecture 10.
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.
More Classes in C++ Bryce Boe 2012/08/20 CS32, Summer 2012 B.
Programming Languages and Paradigms Object-Oriented Programming.
Chapter 13: Pointers, Classes, Virtual Functions, and Abstract Classes
C++ Programming: Program Design Including Data Structures, Fourth Edition Chapter 13: Pointers, Classes, Virtual Functions, and Abstract 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.
Pointer Data Type and Pointer Variables
Learners Support Publications Pointers, Virtual Functions and Polymorphism.
CSE 425: Object-Oriented Programming II Implementation of OO Languages Efficient use of instructions and program storage –E.g., a C++ object is stored.
C++ Programming: From Problem Analysis to Program Design, Fourth Edition Chapter 14: Pointers, Classes, Virtual Functions, and Abstract Classes.
Polymorphism. Introduction ‘one name multiple forms’ Implemented using overloaded functions and operators Early binding or static binding or static linking.
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.
1 Chapter 10: Data Abstraction and Object Orientation Aaron Bloomfield CS 415 Fall 2005.
Object Oriented Programming with C++/ Session 6 / 1 of 44 Multiple Inheritance and Polymorphism Session 6.
CSE 425: Object-Oriented Programming I Object-Oriented Programming A design method as well as a programming paradigm –For example, CRC cards, noun-verb.
Java™ How to Program, 9/e Presented by: Dr. José M. Reyes Álamo © Copyright by Pearson Education, Inc. All Rights Reserved.
Unit IV Unit IV: Virtual functions concepts, Abstracts classes & pure virtual functions. Virtual base classes, Friend functions, Static functions, Assignment.
OOP and Dynamic Method Binding Chapter 9. Object Oriented Programming Skipping most of this chapter Focus on 9.4, Dynamic method binding – Polymorphism.
Data Structures Using C++ 2E Chapter 3 Pointers. Data Structures Using C++ 2E2 Objectives Learn about the pointer data type and pointer variables Explore.
Chapter 12: Pointers, Classes, Virtual Functions, and Abstract Classes.
Chapter 10 Inheritance and Polymorphism
Object Oriented Software Development
C/C++ 3 Yeting Ge. Static variables Static variables is stored in the static storage. Static variable will be initialized once. 29.cpp 21.cpp.
Copyright © 2012 Pearson Education, Inc. Chapter 15: Inheritance, Polymorphism, and Virtual Functions.
Programming with Java © 2002 The McGraw-Hill Companies, Inc. All rights reserved. 1 McGraw-Hill/Irwin Chapter 5 Creating Classes.
CS451 - Lecture 2 1 CS451 Lecture 2: Introduction to Object Orientation Yugi Lee STB #555 (816) * Acknowledgement:
Sadegh Aliakbary Sharif University of Technology Spring 2011.
OOP using C Abstract data types How to accomplish the task??? Requirements Details Input, output, process Specify each task in terms of input.
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.
Interfaces Chapter 9. 9 Creating Interfaces An interface is a contract. Every class that implements the interface must provide the interface’s defined.
CS212: Object Oriented Analysis and Design Lecture 16: Runtime Polymorphism.
Overview of C++ Polymorphism
Recap Introduction to Inheritance Inheritance in C++ IS-A Relationship Polymorphism in Inheritance Classes in Inheritance Visibility Rules Constructor.
CSCI 171 Presentation 15 Introduction to Object–Oriented Programming (OOP) in C++
Polymorphism and Virtual Functions One name many shapes behaviour Unit - 07.
Lecture 2 Intro. To Software Engineering and Object-Oriented Programming (2/2)
Chapter 12: Pointers, Classes, Virtual Functions, Abstract Classes, and Lists.
MAITRAYEE MUKERJI Object Oriented Programming in C++: Hierarchy / Inheritance.
CSCI-383 Object-Oriented Programming & Design Lecture 17.
CPSC 252Inheritance II Page 1 Inheritance & Pointers Consider the following client code: const int MAXCLOCKS = 2; Clock* clockPtr[ MAXCLOCKS ]; clockPtr[0]
A First Book of C++ Chapter 12 Extending Your Classes.
Chapter 12: Support for Object- Oriented Programming Lecture # 18.
SEG4110 – Advanced Software Design and Reengineering TOPIC I Introduction to C++ For those who know Java And OO Principles in General.
Inheritance Modern object-oriented (OO) programming languages provide 3 capabilities: encapsulation inheritance polymorphism which can improve the design,
Polymorphism, Abstract Classes & Interfaces
OOP What is problem? Solution? OOP
CS212: Object Oriented Analysis and Design
Inheritance Modern object-oriented (OO) programming languages provide 3 capabilities: encapsulation inheritance polymorphism which can improve the design,
Chapter 12: Pointers, Classes, Virtual Functions, and Abstract Classes
Basic C++ What’s a declaration? What’s a definition?
Virtual Functions Department of CSE, BUET Chapter 10.
Polymorphism, Abstract Classes & Interfaces
Indirection.
9: POLYMORPHISM Programming Technique II (SCSJ1023) Jumail Bin Taliba
Overview of C++ Polymorphism
Chapter 11 Class Inheritance
Jim Fawcett CSE687 – Object Oriented Design Spring 2014
C++ Object Oriented 1.
Presentation transcript:

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 output The behavior of the program is important We need to define how an item operates An item specified in terms of operations is an Abstract Data Type

Encapsulation Combining of data and related operations is called data encapsulation An object is an instance of a class An object is an instance of a class In OO languages a connection between data and member functions at the outset This allows for modeling fragments of the real world It allows for easier error finding We also can conceal details from other people

Inheritance OOLs allow for creating a hierarchy of classes The first class in the hierarchy is called the base class. Other classes are called subclasses or derived classes

Pointers Pointers are variables that contain the address of another variable We can use the pointer variable to indirectly access the value being referenced by the pointer Pointers and arrays are similar.

Pointers To create a pointer variable we use the keyword new When you want to free the memory we use the keyword delete It is an error to try to use an address that is stored in a pointer after the delete command has been issued

Pointer vs. Array for ( sum = a[0], i = 1; i < 5; i++ ) sum += a[i]; for ( sum = *a, i = 1; i < 5; i++ ) sum += *(a + i); for ( sum = *a, p = a+1; p < a+5; p++ ) sum += *p;

Why does this work? a + 1 denotes the next cell of the array. a + 1 is equivalent to &a[1] So if a = 1020, then a + 1 may not necessarily by The value will depend on the type stored in a and its sizeof value

Other pointer issues When we are dealing with dynamic data, we have issues Classes that contain dynamic data must always have a copy constructor They also must have a destructor and an assignment operator The class must take care of its data

Polymorphism Polymorphism refers to how a function name can denote many functions that are members of different objects This works because of the type of binding Static binding is determined at compile time Dynamic binding is determined at run time In order to use dynamic binding, we need two conditions to be met: Functions must be declared as virtual Functions must be declared as virtual A pointer to the object is used A pointer to the object is used