Object-Oriented Programming Basics

Slides:



Advertisements
Similar presentations
Object orientation and persistent objects Dragos Chirila Finsiel Romania Copenhagen, 24 May 2004.
Advertisements

Object-Oriented Programming Basics Prof. Ankur Teredesai, Computer Science Department, RIT.
Stereotypes Stereotypes provide the capability to create a new kind of modeling element. –They can be used to classify or mark modeling elements. –A type.
Classes & Objects Computer Science I Last updated 9/30/10.
Classes and Object- Oriented... tMyn1 Classes and Object-Oriented Programming The essence of object-oriented programming is that you write programs in.
Chapter 10 Introduction to Objects and Classess 1.
ITEC200 – Week03 Inheritance and Class Hierarchies.
L3-1-S1 OO Concepts © M.E. Fayad SJSU -- CMPE Software System Engineering Dr. M.E. Fayad, Professor Computer Engineering Department, Room.
Road Map Introduction to object oriented programming. Classes
Object Classes In UML. Object Concepts What is an object? How do objects communicate? How is an object’s interface defined? What have objects to do with.
OOP in Java Nelson Padua-Perez Chau-Wen Tseng Department of Computer Science University of Maryland, College Park.
C++ Training Datascope Lawrence D’Antonio Lecture 4 An Overview of C++: What is a Class/Object?
7M701 1 Class Diagram advanced concepts. 7M701 2 Characteristics of Object Oriented Design (OOD) objectData and operations (functions) are combined 
Chapter 10 Classes Continued
Modelling classes Drawing a Class Diagram. Class diagram First pick the classes –Choose relevant nouns, which have attributes and operations. Find the.
8.1 Classes & Inheritance Inheritance Objects are created to model ‘things’ Sometimes, ‘things’ may be different, but still have many attributes.
OOP in Java Fawzi Emad Chau-Wen Tseng Department of Computer Science University of Maryland, College Park.
State,identity and behavior of objects Sem III K.I.R.A.S.
CSM-Java Programming-I Spring,2005 Introduction to Objects and Classes Lesson - 1.
BCS 2143 Introduction to Object Oriented and Software Development.
OBJECT ORIENTED PROGRAMMING CONCEPTS ISC 560. Object-oriented Concepts  Objects – things names with nouns  Classes – classifications (groups) of similar.
Introduction to Object Oriented Programming. Object Oriented Programming Technique used to develop programs revolving around the real world entities In.
Database Management System Prepared by Dr. Ahmed El-Ragal Reviewed & Presented By Mr. Mahmoud Rafeek Alfarra College Of Science & Technology Khan younis.
Specialization and Inheritance Chapter 8. 8 Specialization Specialized classes inherit the properties and methods of the parent or base class. A dog is.
11 Chapter 11 Object-Oriented Databases Database Systems: Design, Implementation, and Management 4th Edition Peter Rob & Carlos Coronel.
CSCI-383 Object-Oriented Programming & Design Lecture 13.
OOP Class Lawrence D’Antonio Lecture 3 An Overview of C++
RIT Computer Science Dept. Goals l Inheritance l Modifiers: private, public, protected l Polymorphism.
Design Model Lecture p6 T120B pavasario sem.
Object Oriented Analysis and Design Class and Object Diagrams.
CS451 - Lecture 2 1 CS451 Lecture 2: Introduction to Object Orientation Yugi Lee STB #555 (816) * Acknowledgement:
1 Overview of Object-Oriented Software Design and Java Programming Putting the Pieces Together!
Object-Oriented Programming Chapter Chapter
Inheritance CSI 1101 Nour El Kadri. OOP  We have seen that object-oriented programming (OOP) helps organizing and maintaining large software systems.
1 Software Engineering Lecture 15 Object Oriented Software Design in Java.
Inheritance and Class Hierarchies Chapter 3. Chapter 3: Inheritance and Class Hierarchies2 Chapter Objectives To understand inheritance and how it facilitates.
COP 4331 – OOD&P Lecture 7 Object Concepts. What is an Object Programming language definition: An instance of a class Design perspective is different.
 Description of Inheritance  Base Class Object  Subclass, Subtype, and Substitutability  Forms of Inheritance  Modifiers and Inheritance  The Benefits.
Geoff Holmes and Bernhard Pfahringer COMP206-08S General Programming 2.
Object-oriented programming (OOP) is a programming paradigm using "objects" – data structures consisting of data fields and methods together with their.
Object-Oriented Design
Unified Modeling Language (UML)
Sections Inheritance and Abstract Classes
JAVA By Waqas.
Inheritance ITI1121 Nour El Kadri.
Lecture 12 Inheritance.
Objects as a programming concept
Systems Analysis and Design With UML 2
Final and Abstract Classes
The Object-Oriented Thought Process Chapter 1
Chapter 11 Object-Oriented Design
Systems Analysis and Design With UML 2
Chapter 3: Using Methods, Classes, and Objects
Object Oriented Programming in Java
PRINCIPALES OF OBJECT ORIENTED PROGRAMMING
Road Map Inheritance Class hierarchy Overriding methods Constructors
ATS Application Programming: Java Programming
Chapter 13 Abstract Classes and Interfaces
Corresponds with Chapter 7
Chapter 10 Thinking in Objects
Lec 3: Object-Oriented Data Modeling
Software Engineering System Modeling Extra examples Dr.Doaa Sami
Object Oriented Analysis and Design
CS 112 Programming 2 Lecture 02 Abstract Classes & Interfaces (2)
CMSC202 Computer Science II for Majors Lecture 10 and 11 – Inheritance
Object-Oriented PHP (1)
Final and Abstract Classes
Object Oriented System Design Class Diagrams
CS 4310: Software Engineering
Presentation transcript:

Object-Oriented Programming Basics Prof. Ankur Teredesai, Computer Science Department, RIT.

Classes and Objects Class <CAR>

Objects The term object is not easily defined According to Webster: Object: a visible or tangible thing of relative stable form; A thing that may be apprehended intellectually; A thing to which thought or action is directed In this class, we will use the following definition: An object has state, behavior, and identity (Booch)

<Ford_Mustang> Classes and Objects Object <7_series_BMW> Object <VW_Beetle> Object <Ford_Mustang>

State The state of an object encompasses all of the (static) properties of the object plus the current (dynamic) values of each of these properties A property is an inherent or distinctive characteristic, trait, quality, or feature that contribute to making an object uniquely that object We will use the word attribute, or data member, to refer to the state of an object State of the object Ford_Mustang is THIS COOL LOOKING RED Ford_Mustang. A property of THIS Mustang is its Color. Attribute is another name for the property e.g. color.

Examples Properties ( Attributes ) : Values Elevators travel up or down Vending machines accept coins Clocks indicate the current time Values Current floor Number of coins deposited The number of minutes since the last hour

“Start the engine of the BMW” Messages to Objects Object <7_series_BMW> “Start the engine of the BMW” Start_Engine

Method of a Class Class <CAR> Start_Engine

Behavior Behavior is how an object acts and reacts, in terms of state changes and interactions with other objects. An operation is some action that one object performs upon another in order to elicit a reaction. We will use the word method to describe object behavior in java. Invoking a method causes the behavior to take place.

Types of Methods There are 4 basic types of methods: Modifier (sometimes called a mutator) Changes the value associated with an attribute of the object E.g. A method like Change_Car_Color Accessor Returns the value associated with an attribute of the object E.g. A method like Price_of_Car Constructor Called once when the object is created (before any other method will be invoked) E.g. Car(Mustang) Destructor Called when the object is destroyed E.g.~Car( )

Identity Identity is the property of an object that distinguishes it from all other objects. The failure to recognize the difference between the name of the object and the object itself is the source of many errors in object-oriented (OO) programming.

Assignment and Equality What does it mean to assign one object to another? Copy the name only (shallow copy) Duplicate the object, creating a different object (with a different name) whose state and behavior is the same as the original (deep copy) Equality like assignment, can mean two things Two names designate the same object Two objects are different but their state and behavior are the same

Relationships Objects contribute to the behavior of a system by collaborating with one another A car is a collection of parts like the Engine, Steering Wheel, Wipers,Wheels each sending messages to each other so that the car can be driven!! The relationship between any two objects encompasses the assumptions that each makes about the other, including what operations can be performed and what behavior results from it.

Relationships There are two kinds of relationships that are of particular interest. Using relationship E.g. Owner uses the Car. Containing relationship E.g. Car contains an Engine

Therefore a Class is? According to Webster A group, set, or kind marked by common attributes or a common attribute A class is a set of objects that share a common structure and a common behavior An object is a concrete entity that exists in space and time, an instance of a class A class represents only an abstraction, the essence of an object from the class

Class A class can be thought of as a cookie cutter, form which objects can be instantiated A class is to an object, as a blueprint is to a building The class mammal represents the characteristics common to all mammals Live birth, nurse young, have hair, … “Paul”, “PJ”, “Lisa”, “Heidi”, and “James” are specific instances from the class mammal

Class Relationships Consider for a moment the following classes Flowers Daisies Red roses Yellow roses Petals What observations can you make?

Kinds of Relationships Classes, like objects, do not exist in isolation. Relations between classes can be made for one of two reasons. To indicate some sort of sharing. A yellow rose and a red rose are both roses and have petals, roots, leaves, thorns, etc. Some kind of semantic connection. Daisies and roses are both flowers that are pollinated in the same way.

Kinds of Class Relationships There are three basic kinds of class relationships Generalization (“kind of”) A rose is a kind-of a flower Generalization provides the ability to create subclasses Subclasses share the structure of the parent class Aggregation (“part of”) A petal is part-of a rose Aggregation allows one to construct new classes from existing one Association

Inheritance The term, inheritance, is used in many object oriented (OO) programming languages to describe the generalization relationship Inheritance is a relationship where one class shares the structure or behavior defined in one class (single inheritance) or more (multiple inheritance)

Types of Inheritance Description Specification Specialization Form of Inheritance Description Specification The superclass defines behavior that is implemented in the subclass but not in the superclass. Provides a way to guarantee that subclass implement the same behavior. Specialization The subclass is a specialized form of the superclass but satisfies the specifications of the parent class in all relevant aspects. Extension The subclass adds new functionality to the parent class, but does not change any inherited behavior. Limitation The subclass restricts the use of some of the behavior inherited from the superclass. Combination The subclass inherits features from more than one superclass (i.e. multiple inheritance).

Benefits of Inheritance One view of inheritance is that it provides a way to specify some properties/behaviors that all subclasses must exhibit Inheritance can be used to re-use code Inheritance also provides the ability to generalize A method can be written to work with the super-class but subclasses can be passed as arguments

Views of a Class A class can be viewed as a sort of contract that specifies what instances of the class can, and cannot do It is possible to distinguish between the outside and inside view of a class The interface of a class provides its outside view and emphasizes the abstraction The implementation of a class is its inside view

Access Most classes provide three levels of access to their members (state and behavior): Public The part of the class of the class that is visible to all clients of the class Protected The part of the class that is only visible to subclasses of the class Private A part of the class that is not visible to any other classes