1 Object-Oriented Programming OOP. 2 Object-oriented programming is a new paradigm for program development in which the focus is on the data instead of.

Slides:



Advertisements
Similar presentations
Object Oriented Programming
Advertisements

1 Classes and Data Abstraction Chapter What a Class ! ! Specification and implementation Private and public elements Declaring classes data and.
C++ Classes & Data Abstraction
Overview of Data Structures and Algorithms
Composition CMSC 202. Code Reuse Effective software development relies on reusing existing code. Code reuse must be more than just copying code and changing.
Object Oriented Programming in Java. Object Oriented Programming Concepts in Java Object oriented Programming is a paradigm or organizing principle for.
Programming Languages Marjan Sirjani 2 2. Language Design Issues Design to Run efficiently : early languages Easy to write correctly : new languages.
Classes & Objects Computer Science I Last updated 9/30/10.
Object Oriented Programming A brief review of what you should know about OOP.
Chapter 3 Data Abstraction: The Walls. © 2005 Pearson Addison-Wesley. All rights reserved3-2 Abstract Data Types Modularity –Keeps the complexity of a.
1 Chapter 11 Structured Types, Data Abstraction and Classes Dale/Weems/Headington.
OOP in Java Nelson Padua-Perez Chau-Wen Tseng Department of Computer Science University of Maryland, College Park.
OOP Etgar 2008 – Recitation 11 Object Oriented Programming Etgar 2008 Recitation 1.
Abstract Data Type (ADT). 2 An Abstract Data Type (ADT) is a data structure with a set of operations –Operations specify how the ADT behaves, but does.
OOP in Java Fawzi Emad Chau-Wen Tseng Department of Computer Science University of Maryland, College Park.
OBJECT ORIENTED PROGRAMMING
CSC241: Object Oriented Programming
Programming Languages and Paradigms Object-Oriented Programming.
“is a”  Define a new class DerivedClass which extends BaseClass class BaseClass { // class contents } class DerivedClass : BaseClass { // class.
Introduction to Object-oriented programming and software development Lecture 1.
Introduction to Object Oriented Programming. Object Oriented Programming Technique used to develop programs revolving around the real world entities In.
CSC 212 Object-Oriented Programming and Java Part 1.
Chapter 6 Object-Oriented Java Script JavaScript, Third Edition.
Data Design and Implementation. Definitions of Java TYPES Atomic or primitive type A data type whose elements are single, non-decomposable data items.
Copyright 2004 Scott/Jones Publishing Alternate Version of STARTING OUT WITH C++ 4 th Edition Chapter 7 Structured Data and Classes.
C++ Lecture 4 Tuesday, 15 July Struct & Classes l Structure in C++ l Classes and data abstraction l Class scope l Constructors and destructors l.
1 Chapter Structured Types, Data Abstraction and Classes Dale/Weems.
P Chapter 2 introduces Object Oriented Programming. p OOP is a relatively new approach to programming which supports the creation of new data types and.
Design.ppt1 Top-down designs: 1. Define the Problem IPO 2. Identify tasks, Modularize 3. Use structure chart 4. Pseudocode for Mainline 5. Construct pseudocode.
Topic 1 Object Oriented Programming. 1-2 Objectives To review the concepts and terminology of object-oriented programming To discuss some features of.
Chapter 4 Introduction to Classes, Objects, Methods and strings
Introduction to c++ programming - object oriented programming concepts - Structured Vs OOP. Classes and objects - class definition - Objects - class scope.
Programming Paradigms Lecturer Hamza Azeem. What is PP ? Revision of Programming concepts learned in CPLB Learning how to perform “Object-Oriented Programming”
Lecture 10 Concepts of Programming Languages Arne Kutzner Hanyang University / Seoul Korea.
Object-Oriented Programming. Objectives Distinguish between object-oriented and procedure-oriented design. Define the terms class and object. Distinguish.
OOP (Object Oriented Programming) Lecture 1. Why a new paradigm is needed? Complexity Five attributes of complex systems –Frequently, complexity takes.
Inheritance CSI 1101 Nour El Kadri. OOP  We have seen that object-oriented programming (OOP) helps organizing and maintaining large software systems.
Data Design and Implementation. Definitions Atomic or primitive type A data type whose elements are single, non-decomposable data items Composite type.
1 Classes II Chapter 7 2 Introduction Continued study of –classes –data abstraction Prepare for operator overloading in next chapter Work with strings.
OO in Context Lecture 13: Dolores Zage. Confused about OO Not alone, there is much confusion about OO many programs are claimed to be OO but are not really.
Topic 1 Object Oriented Programming. 1-2 Objectives To review the concepts and terminology of object-oriented programming To discuss some features of.
Basic Concepts of OOP.  Object-Oriented Programming (OOP) is a type of programming added to php5 that makes building complex, modular and reusable web.
Learning OOP in PHP. What is OOP? OOP stands for Object Oriented Programming. OOP is a programming paradigm wherein you create “objects” to work with.
OBJECT ORIENTED PROGRAMMING. Design principles for organizing code into user-defined types Principles include: Encapsulation Inheritance Polymorphism.
Programming Fundamentals1 Chapter 7 INTRODUCTION TO CLASSES.
Lecture 2 Intro. To Software Engineering and Object-Oriented Programming (2/2)
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.
1 Classes and Data Abstraction Chapter What a Class ! ! Specification and implementation Private and public elements Declaring classes data and.
CPS120: Introduction to Computer Science Lecture 16A Object-Oriented Concepts.
9.1 CLASS (STATIC) VARIABLES AND METHODS Defining classes is only one aspect of object-oriented programming. The real power 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)
Object-oriented programming (OOP) is a programming paradigm using "objects" – data structures consisting of data fields and methods together with their.
1 Chapter 12 Classes and Abstraction. 2 Chapter 12 Topics Meaning of an Abstract Data Type Declaring and Using a class Data Type Using Separate Specification.
Chapter 12 Classes and Abstraction
Programming Logic and Design Seventh Edition
OOP What is problem? Solution? OOP
Review: Two Programming Paradigms
11.1 The Concept of Abstraction
Object Oriented Concepts -I
Object-Oriented Programming: Classes and Objects
CS212: Object Oriented Analysis and Design
Classes and Data Abstraction
IFS410: Advanced Analysis and Design
Object-Oriented Programming
10.2 const (Constant) Objects and const Member Functions
Object-Oriented Programming
Object-Oriented Programming
Object-Oriented PHP (1)
Presentation transcript:

1 Object-Oriented Programming OOP

2 Object-oriented programming is a new paradigm for program development in which the focus is on the data instead of the functions and control flow.

3 All programming can be considered as the process of modeling objects in the real world (or now, in virtual worlds).

4 The word “objects” is being used in a very broad sense here. Cars, elevators, and dice can be objects, but so also can dates, times and addresses.

5 If we seek to model a car, we try to capture 2 aspects of “carness” – attributes and capabilities.

6 Attributes are characteristics of a car that we want to deal with while ignoring other characteristics that do not matter to us in our modeling. -- Abstraction – e.g. year, make, model, color, mileage, doors, horsepower,…

7 Capabilities are actions performed by, for or on an object. They often have the effect of changing one or more attributes of an object. For a car, this might be – drive, stop, go, fill up, change gears, lock, paint, wreck, …

8 In OOP, rather than define a particular car like my Canery, we define a class called Car. That class is a template that we can use to construct my Camery and your Jeep …

9 When we define a class we are really defining a new data type like int, char, float, … It’s just one that YOU create from scratch and decide how it works and what it will do. Actually, the strings we have been using are a class that a programmer developed.

10 Abstract Data Type (ADT) l An abstract data type is a data type whose properties (domain and operations) are specified (what) independently of any particular implementation (how)

11 When we designate an attribute we have to specify a domain of values that that attribute can have. For Color, the domain might be {Red, Blue, Green, Yellow, Orange} For Mileage the domain would be float.

Several Possible Representations of ADT Time 3 int variables 3 strings 3-element int array Choice of representation depends on time, space, and algorithms needed to implement operations “10” “45” “27”

13 OK, now for some examples.

14 class cars { private: double gas_mileage; //gas mileage in mpg double mileage; //odometer reading double gas_volume; //gas volume in gallons public: cars(double, double, double); //constructor func. public: ~cars(void); //destructor function void drive(double); //prototype for drive function }; Data members Function members

15 The word public means that this information is exposed to other programs can refer to it. Private means that this information is not available to other programs. This is a lot like local scope. Generally, data members are private and function member prototypes are public. However, the actual definitions of the function members is not available to any program outside the class definition. This means that the implementation of these member functions can be changed without having any possible effect on any program that makes use of the class, except for speed of execution (assuming a correct program). Keeping this information hidden is sometimes called encapsulation.

16 cars::cars(double new_gas_mileage, double new_mileage, double new_gas_volume) { gas_mileage = new_gas_mileage; mileage = new_mileage; gas_volume = new_gas_volume; }

17 void cars::drive(double distance) //this function results in the car being driven //distance miles. It must modify the internal variables //accordingly { //amount of gas cosumed double g_consum = distance/gas_mileage; if (g_consum < gas_volume) { mileage += distance; //increase mileage on odometer gas_volume -= g_consum; } else { mileage += gas_volume*gas_mileage; gas_volume = 0; }

18 void main() { cars civic(39, 0, 10); //construct a Honda Civic object civic.drive(300); } Here we use the cars constructor to create an instance (also called class instance, or object instance or object) called civic. civic is an object variable. You can create as many object instances of a class as you want.

19 One last characteristic of OOP that I will mention is called Inheritance. Inheritance allows a programmer to extend the definition of a class to extend or specialize it, JUST by adding the new data members and function members that are needed. So, from the Car class, we could derive a new class Hybrid, by adding just the new stuff and inheriting from the old class Car.

20 C++ classType l Facilitates re-use of C++ code for an ADT l Software that uses the class is called a client l Client code uses class’s public member functions to manipulate class objects