Introduction to Object Oriented Programming CIS 230 01-03-06.

Slides:



Advertisements
Similar presentations
C++ Classes & Data Abstraction
Advertisements

Objectives Introduction to Inheritance and Composition (Subclasses and SuperClasses) Overriding (and extending), and inheriting methods and constructors.
Road Map Introduction to object oriented programming. Classes
Encapsulation, Inheritance & Interfaces CSE 115 Spring 2006 February 27, March 1 & 3, 2006.
1 Introduction to C++ Programming Concept Basic C++ C++ Extension from C.
C++ fundamentals.
1 Chapter 8 Objects and Classes. 2 Motivations After learning the preceding chapters, you are capable of solving many programming problems using selections,
OBJECT ORIENTED PROGRAMMING IN C++ LECTURE
Object Oriented Programming using VC++. Introduction Program – Set of instruction written in a high level language High level language used for writing.
CIT241 Prerequisite Knowledge ◦ Variables ◦ Operators ◦ C++ Syntax ◦ Program Structure ◦ Classes  Basic Structure of a class  Concept of Data Hiding.
Programming Paradigms Imperative programming Functional programming Logic programming Event-driven programming Object-oriented programming A programming.
Lecture 3. 2 Introduction Java is a true OO language -the underlying structure of all Java programs is classes. Everything must be encapsulated in a class.
Programming Languages and Paradigms Object-Oriented Programming.
CSM-Java Programming-I Spring,2005 Introduction to Objects and Classes Lesson - 1.
Chapter 11: Inheritance and Composition. Objectives In this chapter, you will: – Learn about inheritance – Learn about derived and base classes – Redefine.
Introduction to Object-oriented programming and software development Lecture 1.
Inheritance Joe Meehean. Object Oriented Programming Objects state (data) behavior (methods) identity (allocation of memory) Class objects definition.
11 Chapter 11 Object-Oriented Databases Database Systems: Design, Implementation, and Management 4th Edition Peter Rob & Carlos Coronel.
Chapter 8. About the Midterm Exam.. Exam on March 12 Monday (Tentatively) Review on March 7 Wednesday Cover from Chapter 6 Grades will be out before spring.
1 Classes and Objects in C++ 2 Introduction Java is a true OO language and therefore the underlying structure of all Java programs is classes. Anything.
Copyright © 2012 Pearson Education, Inc. Chapter 13: Introduction to Classes.
Introduction To Classes Chapter Procedural And Object Oriented Programming Procedural programming focuses on the process/actions that occur in a.
1 Chapter 13 Introduction to Classes. 2 Topics 12.1 Procedural and Object-Oriented Programming 12.2 Introduction to Classes 12.3 Defining an Instance.
Copyright 2003 Scott/Jones Publishing Standard Version of Starting Out with C++, 4th Edition Chapter 13 Introduction to Classes.
Chapter 13. Procedural programming vs OOP  Procedural programming focuses on accomplishing tasks (“verbs” are important).  Object-oriented programming.
SNPL1 Woochang Lim What (Variable) + How (Function) = Object Objects are the physical and conceptual things we find in the universe around us. Object-Oriented.
Copyright 2004 Scott/Jones Publishing Alternate Version of STARTING OUT WITH C++ 4 th Edition Chapter 7 Structured Data and Classes.
SMIE-121 Software Design II School of Mobile Information Engineering, Sun Yat-sen University Lecture.
C++ Programming Basic Learning Prepared By The Smartpath Information systems
Applications Development
ITEC 3220A Using and Designing Database Systems Instructor: Prof Z. Yang Course Website: 3220a.htm
1 Abstract Data Types & Object Orientation Abstract Data Types (ADT) Concepts –Data Abstraction –ADT in PLs –Encapsulation Object Orientation –Principal.
ITEC 3220A Using and Designing Database Systems Instructor: Gordon Turpin Course Website: Office: CSEB3020.
Introduction to c++ programming - object oriented programming concepts - Structured Vs OOP. Classes and objects - class definition - Objects - class scope.
1 Classes and Data Abstraction 2 Objectives Understand encapsulation and data hiding Understand data abstraction and Abstract Data Types (ADTs) Create.
: Maha Sabri Altememe Lecturer : Maha Sabri Altememe Lecture :1 1.
Chapter 12 Support for Object-Oriented Programming.
1 OOP - An Introduction ISQS 6337 John R. Durrett.
Copyright 2003 Scott/Jones Publishing Standard Version of Starting Out with C++, 4th Brief Edition Chapter 12 Introduction to Classes.
ISBN Object-Oriented Programming Chapter Chapter
C++ Class. © 2005 Pearson Addison-Wesley. All rights reserved 3-2 Abstract Data Types Figure 3.1 Isolated tasks: the implementation of task T does not.
نظام المحاضرات الالكترونينظام المحاضرات الالكتروني Introduction to Object Oriented Programming (OOP) Object Oriented programming is method of programming.
Session 18 Lab 9 Re-cap, Chapter 12: Polymorphism & Using Sound in Java Applications.
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 7: Introduction to Classes and Objects Starting Out with C++ Early.
Chapter 5 Classes and Methods II Lecture Slides to Accompany An Introduction to Computer Science Using Java (2nd Edition) by S.N. Kamin, D. Mickunas, E.
Object-Oriented Programming (OOP) What we did was: (Procedural Programming) a logical procedure that takes input data, processes it, and produces output.
Classes, Interfaces and Packages
1 CSE Programming in C++. 2 Overview Sign roster list Syllabus and Course Policies Introduction to C++ About Lab 1 Fill Questionnaire.
Chapter 11: Inheritance and Composition. Introduction Two common ways to relate two classes in a meaningful way are: – Inheritance (“is-a” relationship)
Object Oriented Programming. OOP  The fundamental idea behind object-oriented programming is:  The real world consists of objects. Computer programs.
OBJECT ORIENTED PROGRAMMING. Design principles for organizing code into user-defined types Principles include: Encapsulation Inheritance Polymorphism.
Matthew Small Introduction to Object-Oriented Programming.
Monday, Jan 27, 2003Kate Gregory with material from Deitel and Deitel Week 4 Questions from Last Week Hand in Lab 2 Classes.
OOP Basics Classes & Methods (c) IDMS/SQL News
An Introduction to Programming with C++ Fifth Edition Chapter 14 Classes and Objects.
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 n Object Oriented Programming. 2 Introduction n procedure-oriented programming consists of writing a list of instructions and organizing these instructions.
Seventh step for Learning C++ Programming CLASS Declaration Public & Private Constructor & Destructor This pointer Inheritance.
INTRODUCTION Java is a true OO language the underlying structure of all Java programs is classes. Everything must be encapsulated in a class that defines.
Object-oriented programming (OOP) is a programming paradigm using "objects" – data structures consisting of data fields and methods together with their.
Classes C++ representation of an object
Classes and OOP.
11.1 The Concept of Abstraction
INTRODUCTION TO OBJECT-ORIENTED PROGRAMMING (OOP) & CONCEPTS
HIGHLEVEL REVIEW Chapter 9 Objects and Classes
Support for Object-Oriented Programming
ITEC 3220A Using and Designing Database Systems
Classes C++ representation of an object
CPS120: Introduction to Computer Science
11.1 The Concept of Abstraction
Presentation transcript:

Introduction to Object Oriented Programming CIS

Introduction What Makes an object oriented programming language? 1.Objects include both data and instruction 2.Objects inherit behavior from existing classes 3.Objects determine at runtime how to resond to messages

General Types of OOP languages 1.Hybrids C++, Objective C, Object Pascal Provide compatibility with older languages 2.Pure OOP languages Smalltalk, Actor, Java Programmer is forced to create object- oriented code.

Why OOP? User Interface –2/3 of an applications code –(windowing, pull down menus, graphics, etc.) –need to be able to write this easily

Misconceptions 1.Makes everything easy 2.You can reuse everything

Learning curves 1.Must learn the tools provided to create object-oriented programs 2.Must learn to work in an object-oriented programming style

Encapsulation The process of combining both properties (data) and behaviors (functions) into one entity. Examples: Integers – Circle – Check – digits +, -, *, / radius, circumference, area how to calc circumference, how to calc area, … amount, check number, date, comment write, sign, cash, record

Class A definition of an object (or for a group of similar objects) A template for creating objects Note: Each object belongs to only one class

C++ partial examples name might contain: circle might have: what it is how to get to it data – radius how to get the radius calculate circumference calculate area

C++ form class ClassName { private: data public: functions }; This defines a class, nothing exists yet prototypes: to keep the definition compact

Circle class Circle { private: float radius; public: void store_radius(float); float calc_circum(void); float calc_area(void); float return_radius(void); };

Class Functions void Circle::store_radius(float value) { radius = value; } Class Nametwo colons

Class Functions float Circle::calc_circum(void) { float circum; circum = 3.14 * 2 * radius; return circum; } float Circle::calc_area(void) { return (3.14 * radius * radius); } Local variable Local variable wasn’t really needed

Instance –an actual variable of the class void main() { Circle circle1, circle2; float x, y, z, w; … } Each has its own data (i.e. radius) but they share the functions (methods)

Invoking methods instance.method( ); circle1.store_radius(6); cout << “Please enter a circle’s radius ”; cin >> x; circle2.store_radius(x); y = circle1.calc_circum(); z = circle1.calc_area(); cout << “ A 6 inch circle has a circumference \n”; cout << “ of “ << y << “ and an area of “ << z << “\n”;

Invoking methods cout << “A “ << x << “ inch circle has a circumference \n”; cout << “of “ << circle2.calc_circum(); cout << “and an area of “ << circle2.calc_area() << “\n”; cout << “The sum of the two areas is “; w = circle1.calc_area() + circle2.calc_area(); cout << w << ‘\n’;

Message A request to an object Must have at least two parts: 1.an instance name 2.the name of a method Example: first_circle.assign_radius(7); first_circle.calc_area(); they may require more instancemethod

OOP Review Class – A definition (template) of an object –Contains: data & methods  Encapsulation –Data – private –Methods – public Instance (object) – An actual variable of the class –Each instance has its own data but jointly use the methods

OOP Review Data Abstraction – The ability to manipulate the data without knowledge of the data’s internal format –Use methods to assign/retrieve values –Example: circle1.store_radius(6); y = circle1.calc_circum(); z = circle1.calc_area(); Assign Retrieve

Protecting the data Circle circle1, circle2; … cin >> x; circle.store_radius(x); y = circle2.calc_circum(); what if x was -3.4?

Protecting the data A new store_radius() method: Circle::store_radius(float value) { if (value >= 0) radius = value; else radius = -1 * value; }

Constructor Automatically invoked when a new object is created: –when: –or:

Constructor Default Constructor Help establish the link between the specific object and its class’ methods Can initialize data

Constructors Same name as the class Can NOT return anything (not even void) class Circle { private: float radius; public Circle(); … }; Circle::Circle() { radius = 1; //Default - unit circle }

Destructor Automatically invoked when an object goes out of existence –when: –or:

Destructor Default Destructor May cleanup any possible side effects ~ClassName: ~Circle()