CPS120: Introduction to Computer Science

Slides:



Advertisements
Similar presentations
Department of Computer Engineering Faculty of Engineering, Prince of Songkla University 1 5 – Abstract Data Types.
Advertisements

OOP in Java Nelson Padua-Perez Chau-Wen Tseng Department of Computer Science University of Maryland, College Park.
Liang, Introduction to Programming with C++, Second Edition, (c) 2010 Pearson Education, Inc. All rights reserved Chapter 9 Objects and Classes.
 By Wayne Cheng.  Introduction  Five Tenets  Terminology  The foundation of C++: Classes.
1 Review: Two Programming Paradigms Structural (Procedural) Object-Oriented PROGRAM PROGRAM FUNCTION OBJECT Operations Data OBJECT Operations Data OBJECT.
OBJECT ORIENTED PROGRAMMING IN C++ LECTURE
CSM-Java Programming-I Spring,2005 Introduction to Objects and Classes Lesson - 1.
Classes Mark Hennessy Dept. Computer Science NUI Maynooth C++ Workshop 18 th – 22 nd Spetember 2006.
Introduction to Object-oriented programming and software development Lecture 1.
An Object-Oriented Approach to Programming Logic and Design
Engineering H192 - Computer Programming The Ohio State University Gateway Engineering Education Coalition Lect 24P. 1Winter Quarter C++ Lecture 24.
Copyright © 2012 Pearson Education, Inc. Chapter 13: Introduction to Classes.
Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 13: Introduction to Classes.
Copyright 2003 Scott/Jones Publishing Standard Version of Starting Out with C++, 4th Edition Chapter 13 Introduction to Classes.
Copyright 2004 Scott/Jones Publishing Alternate Version of STARTING OUT WITH C++ 4 th Edition Chapter 7 Structured Data and Classes.
CPS120: Introduction to Computer Science Functions.
ADTs and C++ Classes Classes and Members Constructors The header file and the implementation file Classes and Parameters Operator Overloading.
C++ Programming Basic Learning Prepared By The Smartpath Information systems
Object-Oriented Programming. Procedural Programming All algorithms in a program are performed with functions and data can be viewed and changed directly.
1 Programming Paradigms Object Orientated Programming Paradigm (OOP)
Introduction to c++ programming - object oriented programming concepts - Structured Vs OOP. Classes and objects - class definition - Objects - class scope.
1 OOP - An Introduction ISQS 6337 John R. Durrett.
CSci 162 Lecture 10 Martin van Bommel. Procedures vs Objects Procedural Programming –Centered on the procedures or actions that take place in a program.
نظام المحاضرات الالكترونينظام المحاضرات الالكتروني Introduction to Object Oriented Programming (OOP) Object Oriented programming is method of programming.
CPS120: Introduction to Computer Science Lecture 16 Data Structures, OOP & Advanced Strings.
1 CSE Programming in C++. 2 Overview Sign roster list Syllabus and Course Policies Introduction to C++ About Lab 1 Fill Questionnaire.
Object Oriented Programming. OOP  The fundamental idea behind object-oriented programming is:  The real world consists of objects. Computer programs.
1 Introduction to Object Oriented Programming Chapter 10.
Copyright © 2015, 2012, 2009 Pearson Education, Inc., Publishing as Addison-Wesley All rights reserved. Chapter 13: Introduction to Classes.
Structure A Data structure is a collection of variable which can be same or different types. You can refer to a structure as a single variable, and to.
1 C++ Classes & Object Oriented Programming Overview & Terminology.
Mr H Kandjimi 2016/01/03Mr Kandjimi1 Week 3 –Modularity in C++
CPS120: Introduction to Computer Science Lecture 16A Object-Oriented Concepts.
Liang, Introduction to C++ Programming, (c) 2007 Pearson Education, Inc. All rights reserved X 1 Chapter 9 Introduction of Object Oriented Programming.
Chapter 11: Abstract Data Types Lecture # 17. Chapter 11 Topics The Concept of Abstraction Advantages of Abstract Data Types Design Issues for Abstract.
Data Structures Lecture 4: Classes in C++ Azhar Maqsood NUST Institute of Information Technology (NIIT)
Computer Programming II Lecture 5. Introduction to Object Oriented Programming (OOP) - There are two common programming methods : procedural programming.
Object-oriented programming (OOP) is a programming paradigm using "objects" – data structures consisting of data fields and methods together with their.
Introduction to Object-oriented Programming
Procedural and Object-Oriented Programming
Object-Oriented Programming Concepts
Classes C++ representation of an object
C++ Templates.
Classes and OOP.
A First C++ Class – a Circle
Review: Two Programming Paradigms
Introduction to Classes
More about OOP and ADTs Classes
INTRODUCTION TO OBJECT-ORIENTED PROGRAMMING (OOP) & CONCEPTS
PRINCIPALES OF OBJECT ORIENTED PROGRAMMING
Object Oriented Analysis and Design
Object Oriented Analysis and Design
Introduction to Classes
Lecture 22 Inheritance Richard Gesick.
Object-Oriented Programming
More about OOP and ADTs Classes
Chapter 9 Objects and Classes
Object-Oriented Programming
UNIT I OBJECT ORIENTED PROGRAMMING FUNDAMENTALS
CPS120: Introduction to Computer Science
COP 3330 Object-oriented Programming in C++
Object-Oriented Programming
Object-Oriented Programming
Introduction to Classes and Objects
Inheritance and Polymorphism
Classes C++ representation of an object
Object-Oriented PHP (1)
Lecture 8 Object Oriented Programming (OOP)
Presentation transcript:

CPS120: Introduction to Computer Science Object-Oriented Concepts

The Procedural Paradigm The functions and algorithms are the focus, with data viewed as something for the functions to manipulate

Object-Oriented Paradigm Data should be placed inside the objects and that these objects should communicate with each other in the form of messages

Designing a Class Think in an object-oriented way E.g. an answering machine encapsulates the functions of an answering machine with the data (messages). The buttons are the equivalent of sending messages to the machine

Functionality of Object-Oriented Languages Encapsulation Inheritance Polymorphism

Encapsulation Encapsulation is a language feature that enforces information hiding A class is a language construct that is a pattern for an object and provides a mechanism for encapsulating the properties and actions of the object class We instantiate the class Private and public are called access modifiers

Inheritance Inheritance fosters reuse by allowing an application to take an already-tested class and derive a class from it that inherits the properties the application needs Polymorphism: the ability of a language to have duplicate method names in an inheritance hierarchy and to apply the method that is appropriate for the object to which the method is applied

Polymorphism The ability of a language to have duplicate method names in an inheritance hierarchy and to apply the method that is most appropriate for the object which the method is applied

Object-Oriented Design A problem-solving methodology that produces a solution to a problem in terms of self-contained entities called objects An object is a thing or entity that makes sense within the context of the problem For example, a student

Object-Oriented Design A group of similar objects is described by an object class, or class A class contains fields that represent the properties and behaviors of the class A field can contain data value(s) and/or methods (subprograms) A method is a named algorithm that manipulates the data values in the object

OOP Object-oriented programming (OOP) is the process of developing programs using the object-oriented paradigm

OOP Advantages: Reusability Reusability is a major benefit of object-oriented programming

OOP Advantages: Containment Containment is a term used to describe an object that contains one or more objects as members (Passes the 'has-a' rule)

OOP Advantages: Inheritance Inheritance is the term used to describe an object that inherits properties from another object (Passes the 'is-a' rule) The class from which an object inherits properties is called a parent class or base class The class that inherits the properties is called a child class or derived class

Classes The definition of an object is know as a class It is similar to using basic data structures in C++ When you declare an object, you are said to have instantiated it (given it instances) Objects are members of a class Paul Millis, George Bush and George Washington being members of the human being class The design of a class is as important as its implementation

Relationships Between Classes Containment “part-of” An address class may be part of the definition of a student class Inheritance Classes can inherit data and behavior from other classes “is-a”

Including Classes in C++ For classes, the #include directive uses different punctuation for header (.h) files Quotation marks are used when the header file is a source file in the same location as the program source code Angle brackets are used when the header file is one of the compiler's pre-compiled library functions // Open up OOP.CPP // This object-oriented program shows the use of simple objects which // represent circles. #include "circle.h" // contains the Circle class #include <iostream.h> int main() { circle Circle_One; // instanciate 2 objects circle Circle_Two; // of type circle float User_Radius; double Area; cout << "\nWhat is the radius of the the first circle? "; cin >> User_Radius; Circle_One.SetRadius(User_Radius); // Send a message to Circle_One telling // it to set its radius to User_Radius // The ' .' in the line above is called the member selection operator cout << "\nWhat is the radius of the second circle? "; Circle_Two.SetRadius(User_Radius); // Send a message to Circle_Two telling // it to set its radius to User_Radius Area = Circle_One.Area(); // Send a message to Circle_One asking // for its area cout.setf(ios::fixed); cout << "\nThe area of the first circle is " << Area << ".\n"; Area = Circle_Two.Area(); // Send a message to Circle_Two asking cout << "\nThe area of the second circle is " << Area << ".\n"; cout.unsetf(ios::fixed); return(0); }

Using Header Files for Classes Header files normally contain declarations of variables, functions and classes, but not implementations of the functions and classes

Defining a Class Functions and variables that are prototyped and declared in a class definition are called members #ifndef _CIRCLE_H #define _CIRCLE_H const float PI=3.14159; class circle { public: // constructors circle(); // default constructor circle(const circle &); // copy constructor // member functions void SetRadius(float); double Area(); private: // data float radius; }; // default constructor circle::circle() radius = 0.0; } // copy constructor circle::circle(const circle & Object) radius = Object.radius; // Method to set the radius of the circle void circle::SetRadius(float IncomingRadius) radius = IncomingRadius; // Method to find the area of the circle double circle::Area() return(PI*radius*radius); #endif

Public vs Private Private: Cannot be accessed outside the object Public: Can have access to all the variables and functions public: // constructors circle(); // default constructor circle(const circle &); // copy constructor // member functions void SetRadius(float); double Area(); private: // data float radius;

Constructors Allow all data encapsulated within an object to be initialized to preset values so that errors can be avoided

Member Functions Provide a way for a programmer to pass data to and get data from an object Implemented like a normal C++ function Except -- The class name and the scope-resolution operator (: :) precede the function name circle : : circle() // default constructor