CSCI 171 Presentation 15 Introduction to Object–Oriented Programming (OOP) in C++

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.
Inheritance Java permits you to use your user defined classes to create programs using inheritance.
Object-Oriented PHP (1)
Inheritance and Class Hierarchies Chapter 3. Chapter 3: Inheritance and Class Hierarchies2 Chapter Objectives To understand inheritance and how it facilitates.
OOP in Java Nelson Padua-Perez Chau-Wen Tseng Department of Computer Science University of Maryland, College Park.
Object Oriented Programming.  OOP Basic Principles  C++ Classes  September 2004  John Edgar 22.
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.
Aalborg Media Lab 23-Jun-15 Inheritance Lecture 10 Chapter 8.
1 Introduction to C++ Programming Concept Basic C++ C++ Extension from C.
OOP in Java Fawzi Emad Chau-Wen Tseng Department of Computer Science University of Maryland, College Park.
1 An Introduction to Visual Basic Objectives Explain the history of programming languages Define the terminology used in object-oriented programming.
C++ fundamentals.
OOP Languages: Java vs C++
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
Chapter 11: Inheritance and Composition. Objectives In this chapter, you will: – Learn about inheritance – Learn about derived and base classes – Redefine.
BCS 2143 Introduction to Object Oriented and Software Development.
Lecture 8 Inheritance Richard Gesick. 2 OBJECTIVES How inheritance promotes software reusability. The concepts of base classes and derived classes. To.
CSE 332: C++ templates This Week C++ Templates –Another form of polymorphism (interface based) –Let you plug different types into reusable code Assigned.
Introduction to Object Oriented Programming. Object Oriented Programming Technique used to develop programs revolving around the real world entities In.
Static and Dynamic Behavior CMPS Power of OOP Derives from the ability of objects to change their behavior dynamically at run time. Static – refers.
Object Oriented Programming: Java Edition By: Samuel Robinson.
Introduction To System Analysis and Design
Programming Languages and Paradigms Object-Oriented Programming.
Chapter 6 Object-Oriented Java Script JavaScript, Third Edition.
Objects and Classes Chapter 6 CSCI CSCI 1302 – Objects and Classes2 Outline Introduction Defining Classes for Objects Constructing Objects Accessing.
Copyright 2003 Scott/Jones Publishing Standard Version of Starting Out with C++, 4th Edition Chapter 13 Introduction to Classes.
Week 14 - Monday.  What did we talk about last time?  Introduction to C++  Input and output  Functions  Overloadable  Default parameters  Pass.
Java Objects and Classes. Overview n Creating objects that belong to the classes in the standard Java library n Creating your own classes.
An Object-Oriented Approach to Programming Logic and Design Chapter 3 Using Methods and Parameters.
Programming in Java CSCI-2220 Object Oriented Programming.
Chapter 6 Introduction to Defining Classes. Objectives: Design and implement a simple class from user requirements. Organize a program in terms of a view.
1 Chapter Four Creating and Using Classes. 2 Objectives Learn about class concepts How to create a class from which objects can be instantiated Learn.
Programming with Java © 2002 The McGraw-Hill Companies, Inc. All rights reserved. 1 McGraw-Hill/Irwin Chapter 5 Creating Classes.
9-Dec Dec-15  INTRODUCTION.  FEATURES OF OOP.  ORGANIZATION OF DATA & FUNCTION IN OOP.  OOP’S DESIGN.
Object-Oriented Programming Chapter Chapter
1 OOP - An Introduction ISQS 6337 John R. Durrett.
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
Introduction to Object-Oriented Programming Lesson 2.
OOP Review CS 124.
CITA 342 Section 1 Object Oriented Programming (OOP)
Inheritance and Class Hierarchies Chapter 3. Chapter 3: Inheritance and Class Hierarchies2 Chapter Objectives To understand inheritance and how it facilitates.
Inheritance and Class Hierarchies Chapter 3. Chapter Objectives  To understand inheritance and how it facilitates code reuse  To understand how Java.
Basic Concepts of OOP.  Object-Oriented Programming (OOP) is a type of programming added to php5 that makes building complex, modular and reusable web.
Chapter 11: Inheritance and Composition. Introduction Two common ways to relate two classes in a meaningful way are: – Inheritance (“is-a” relationship)
1 C# - Inheritance and Polymorphism. 2 1.Inheritance 2.Implementing Inheritance in C# 3.Constructor calls in Inheritance 4.Protected Access Modifier 5.The.
Recap Introduction to Inheritance Inheritance in C++ IS-A Relationship Polymorphism in Inheritance Classes in Inheritance Visibility Rules Constructor.
Object-Oriented Programming: Inheritance and Polymorphism.
5.1 Basics of defining and using classes A review of class and object definitions A class is a template or blueprint for an object A class defines.
An Introduction to Programming with C++ Fifth Edition Chapter 14 Classes and Objects.
Lecture 2 Intro. To Software Engineering and Object-Oriented Programming (2/2)
Starting Out with C++, 3 rd Edition 1 Chapter 13 – Introduction to Classes Procedural and Object-Oriented Programming Procedural programming is a method.
Object-oriented programming (OOP) is a programming paradigm using "objects" – data structures consisting of data fields and methods together with their.
CPRG 215 Introduction to Object-Oriented Programming with Java Module 3- Introduction to Object Oriented Programming concepts Topic 3.1 Fundamental Concepts.
Inheritance Modern object-oriented (OO) programming languages provide 3 capabilities: encapsulation inheritance polymorphism which can improve the design,
Objects as a programming concept
OOP What is problem? Solution? OOP
Chapter 3: Using Methods, Classes, and Objects
About the Presentations
SNSCT_CSE_PROGRAMMING PARADIGM_CS206
3 Fundamentals of Object-Oriented Programming
Corresponds with Chapter 7
Object-Oriented Programming
Chapter 11: Inheritance and Composition
Object-Oriented Programming
CSCI 130 Classes and Objects.
Presentation transcript:

CSCI 171 Presentation 15 Introduction to Object–Oriented Programming (OOP) in C++

Classes Templates from which programmatic building blocks are constructed –Extension of structures –Model physical entities –Programmer can ‘construct’ instances of the templates Instantiation Class contains: –Attributes (variables) –Behaviors (methods)

Example Write up the attributes and behaviors of a Car class

Objects Actual instance of a class In an object-oriented program objects interact with each other Objects may be constructed from other objects Black box concept –Other objects don’t care how an object performs its tasks, only that it does perform them

Important OOP concepts Encapsulation –The instances of each class have complete control over the accessibility of their attributes and behaviors as defined by the class –Methods and variables act as a cohesive unit Inheritance –Classes can be related in a hierarchical fashion from general to specific Polymorphism –Some instances of classes have the ability to morph themselves into other (related) classes

Encapsulation Access specifiers –public, protected, private Generally speaking –methods are public –variables are private

Inheritance Defining classes from general to specific –Allows for code reuse –Classes lower in a hierarchy obtain all features of higher level classes –All features should be put as high in the hierarchy as possible Create a class hierarchy for all vehicle objects

Polymorphism Assume we have a hierarchy with Animal at the top, and Crocodile and Dog below –An instance of an animal can reference a Crocodile at one time, and a Dog at another –This instance may respond differently to different methods depending on what it is referencing

Identifying Classes Done in design phase –define, design, code, test, document Most difficult part of OOP –must view entire system in OO terms –good initial design leads to highly effective programming –bad initial design leads to wasted time and effort

OOP in C++ Classes consist of 2 parts –Header all data and method signatures, and all corresponding access specification –Body method bodies

OOP in C++ Memory allocation – creating instances –Constructor method Same name as class If a pointer is used – dynamic memory allocation is done automatically using the keyword ‘new’ If non-pointer – static memory allocation is done –Destructor method Same name as class preceded by ~ If a pointer is used –memory is freed using the keyword ‘delete’ If non-pointer – destructor must be called explicitly