Classes and Objects OOAD.

Slides:



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

Overview of Data Structures and Algorithms
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.
Chapter 10 Introduction to Objects and Classess 1.
OOAD Using the UML - Use-Case Analysis, v 4.2 Copyright  Rational Software, all rights reserved 1/18 Use Case Analysis – continued Control Classes.
Chapter 8 Runtime Support. How program structures are implemented in a computer memory? The evolution of programming language design has led to the creation.
ISBN Chapter 11 Abstract Data Types and Encapsulation Concepts.
Rossella Lau Lecture 8, DCO10105, Semester B, DCO10105 Object-Oriented Programming and Design  Lecture 8: Polymorphism & C++ pointer  Inheritance.
C++ Training Datascope Lawrence D’Antonio Lecture 4 An Overview of C++: What is a Class/Object?
Object Oriented Programming.  OOP Basic Principles  C++ Classes  September 2004  John Edgar 22.
Data Abstraction and Object- Oriented Programming CS351 – Programming Paradigms.
Lecture 9 Concepts of Programming Languages
Abstract Data Types and Encapsulation Concepts
State,identity and behavior of objects Sem III K.I.R.A.S.
Object-Oriented Analysis and Design
The chapter will address the following questions:
Objectives Design Class Diagrams Issues in system design Generalization Review UML papers.
Object Oriented Programming Philosophy. Part 1 -- Basic Understanding & Encapsulation.
SEN 909 OO Programming in C++ Final Exam Multiple choice, True/False and some minimal programming will be required.
Basic Semantics Associating meaning with language entities.
CS3773 Software Engineering Lecture 04 UML Class Diagram.
Learners Support Publications Classes and Objects.
UML Class Diagram Trisha Cummings. What we will be covering What is a Class Diagram? Essential Elements of a UML Class Diagram UML Packages Logical Distribution.
ITEC 3220A Using and Designing Database Systems Instructor: Prof Z. Yang Course Website: 3220a.htm
ISBN Chapter 11 Abstract Data Types and Encapsulation Concepts.
Relationships Relationships between objects and between classes.
Object Oriented Analysis and Design Class and Object Diagrams.
Learners Support Publications Object Oriented Programming.
CS451 - Lecture 2 1 CS451 Lecture 2: Introduction to Object Orientation Yugi Lee STB #555 (816) * Acknowledgement:
Object-Oriented Programming Chapter Chapter
ISBN Object-Oriented Programming Chapter Chapter
1 Introduction to Classes. 2 Terms and Concepts A class is... –The most important building block of any object- oriented system. –A description of a set.
1 Software Engineering Lecture 15 Object Oriented Software Design in Java.
Data Design and Implementation. Definitions Atomic or primitive type A data type whose elements are single, non-decomposable data items Composite type.
Programming Fundamentals. Topics to be covered Today Recursion Inline Functions Scope and Storage Class A simple class Constructor Destructor.
What is Object? Using Brian Mitchell’s notes for reference
1 Chapter 11 © 1998 by Addison Wesley Longman, Inc The Concept of Abstraction - The concept of abstraction is fundamental in programming - Nearly.
1 CS Programming Languages Class 22 November 14, 2000.
1 Copyright © 1998 by Addison Wesley Longman, Inc. Chapter 10 Abstraction - The concept of abstraction is fundamental in programming - Nearly all programming.
ISBN Chapter 11 Abstract Data Types and Encapsulation Concepts.
Object Oriented Programming. OOP  The fundamental idea behind object-oriented programming is:  The real world consists of objects. Computer programs.
1 Using const in C++ Classes In the presence of pointers we must take steps to ensure the integrity of the object Can use const method definitions The.
Kyung Hee University Class Diagramming Notation OOSD 담당조교 석사과정 이정환.
UML Fundamental Elements. Structural Elements Represent abstractions in our system. Elements that encapsulate the system's set of behaviors. Structural.
Dynamic Memory Management & Static Class Members Lecture No 7 Object Oriented Programming COMSATS Institute of Information Technology.
ITEC1301 Object-Oriented Systems Construction Lecture Notes #4 1.
Object Lifetimes and Dynamic Objects Lecture-7. Object Lifetimes and Dynamic Objects External (Global) Objects Persistent (in existence) throughout the.
Chapter 5 Introduction to Defining Classes Fundamentals of Java.
MAITRAYEE MUKERJI Object Oriented Programming in C++
Constructors and Destructors
Processes and threads.
Abstract Data Types and Encapsulation Concepts
Object-Oriented Programming Basics
DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING
11.1 The Concept of Abstraction
Lecture 9 Concepts of Programming Languages
Abstract Data Types and Encapsulation Concepts
CSC 205 Programming II Lecture 2 Subclassing.
Abstract Data Types and Encapsulation Concepts
The Object model The Evolution of the Object Model Elements of the Object Model Applying the Object Model.
Constructors and Destructors
Classes and Objects.
ITEC 3220A Using and Designing Database Systems
Introduction to Data Structure
Submitted By : Veenu Saini Lecturer (IT)
Object Oriented System Design Class Diagrams
11.1 The Concept of Abstraction
Lecture 9 Concepts of Programming Languages
Chapter 11 Abstraction - The concept of abstraction is fundamental in
Presentation transcript:

Classes and Objects OOAD

Topics Nature of an Object Relationship among Objects Nature of an Class Relationship among Classes

Nature of an Object Introduction Informal Definition Object is a tangible entity that exhibits some well-defined behavior. From the perspective of human cognition, an object is any of the following: A tangible and/or visible thing Something that may be apprehended intellectually Something toward which thought or action is directed We add to our informal definition the idea that an object models some part of reality and is therefore something that exists in time and space.

Nature of an Object Introduction an object represents an individual, identifiable item, unit, or entity, either real or abstract, with a well-defined role in the problem domain In general, an object as anything with a crisply defined boundary

Nature of an Object Introduction Definition An object has state, behavior, and identity; the structure and behavior of similar objects are defined in their common class; the terms instance and object are interchangeable.

Nature of an Object State The state of an object encompasses all of the (usually static) properties of the object plus the current (usually dynamic) values of each of these properties.

Nature of an Object State A property is an inherent or distinctive characteristic, trait, quality, or feature that contributes to making an object All properties have some value. This value might be a simple quantity, or it might denote another object. we distinguish between objects and simple values simple quantities such as the number 3 are "a temporal, unchangeable, and non-instantiated, whereas objects exist in time, are changeable, have state, are instantiated, and can be created, destroyed, and shared

Nature of an Object State Class Car { ModelName Manufacture CurrentGearNo CurrentSpeed HeadLightStatus }

Nature of an Object State struct PersonnelRecord { char name[100]; int socialSecurityNumber; char department[10]; float salary; } Each part of this structure denotes a particular property of our abstraction of a personnel record.

Nature of an Object State This declaration denotes a class, not an object, because it does not represent a specific instance To declare objects of this class, we write PersonnelRecord deb, dave, jim, tom, krista; Car c1, c2, c3;

Nature of an Object State Here, we have 5 distinct objects (of PersonnelRecord) and 3 (of Car), each of which takes up some amount of space in memory. None of these objects shares its space with any other object, although each of them has the same properties; thus their states have a common representation. All of them can have different values for properties

Nature of an Object State It is good engineering practice to encapsulate the state of an object rather than expose it as in the preceding declaration. For example, we might rewrite that class declaration as follows: class PersonnelRecord { public: char* employeeName() const; int employeeSocialSecurityNumber() const; char* employeeDepartment() const; protected: char name[100]; int socialSecurityNumber; char department[10]; float salary; };

Nature of an Object State all objects within a system encapsulate some state, and all of the state within a system is encapsulated by objects

Nature of an Object Behavior No object exists in isolation. Rather,. objects are acted upon, and themselves act upon other objects Thus, we may say that Behavior is how an object acts and reacts, in terms of its state changes and message passing.

Nature of an Object Behavior In other words, the behavior of an object represents its outwardly visible and testable activity. An operation is some action that one object performs upon another in order to elicit (obtain) a reaction. For example, a client might invoke the operations append and pop to grow and shrink a queue object, respectively.

Nature of an Object Behavior A client might also invoke the operation length, which returns a value denoting the size of the queue object but does not alter the state of the queue itself. We can say that one object is passing a message to another OR invoking the member function of another.

Nature of an Object Behavior Operation = Message = Methods = Member Functions State (present values of properties) of an object affects the behavior E.g., Invalid Password, deny withdrawal; valid allows

Nature of an Object Behavior Types of Operations Modifier An operation that alters the state of an object Selector An operation that accesses the state of an object, but does not alter the state Iterator An operation that permits all parts of an object to be accessed in some well-defined order

Nature of an Object Behavior Types of Operations… Constructor An operation that creates an object and/or initializes its state Destructor An operation that frees the state of an object and/or destroys the object itself

Nature of an Object Behavior Free Sub-programs Functions/Methods that are not part of any specific class (logically) Are non member function that can operate on same or different types of objects including built-in data types. E.g., Copying one Queue Object in another Queue Object

Nature of an Object Behavior Some time logically related free sub programs are grouped in to Class (that has no state) Called as Static The method will be called as ClassName.MethodName rather than ObjectName.MethodName

Nature of an Object Behavior Roles and Responsibility Collectively, all of the methods and free subprograms associated with a particular object comprise its protocol. it is useful to divide this larger protocol into logical groupings of behavior. These collections, which thus partition the behavior space of an object, denote the roles that an object can play.

Nature of an Object Behavior A role is a mask that an object wears, and so defines a contract between an abstraction and its clients. E.g. Bank Account may be Good or Bad Standing. Its Role affects withdrawal operation A person might have different role Employee Customer Administrator

Nature of an Object Behavior Responsibilities are meant to convey a sense of the purpose of an object and its place in the system. The responsibilities of an object are all the services it provides for all of the contracts it supports In other words, state and behavior of an object collectively define the roles that an object may play in the world, which in turn fulfill the abstraction’s responsibilities.

Nature of an Object Behavior objects play many different roles during their lifetime Even n a day, a person plays role of Student Son/Daughter Brother/Sister Friend Etc.

Nature of an Object Behavior we may classify objects as either active or passive. An active object is one that encompasses its own thread of control, whereas a passive object does not. Active objects are generally autonomous, meaning that they can exhibit some behavior without being operated on by another object. Passive objects, on the other hand, can undergo a state change only when explicitly acted on.

Nature of an Object Identity Identity is that property of an object which distinguishes it from all other objects

Nature of an Object Identity Most PL and database System use variable names to distinguish temporary objects, mixing addressability and identity. Most database systems use identifier keys to distinguish persistent objects, mixing data value and identity The failure to recognize the difference between the name of an object and the object itself is the source of many kinds of errors in object oriented programming.

Nature of an Object Identity The following Example demonstrates the importance of maintaining the identity of the objects you create and shows how easily the identity can be irrecoverably lost.

Nature of an Object Identity DisplayItem item1; DisplayItem *item2 = New DisplayItem(Point(75,75)); DisplayItem *item3 = New DisplayItem(Point(100,100)); DisplayItem *item4=0;

Nature of an Object Identity Item1 is changed from (0,0) to (75,75) Item4=Item3 Item4 is changed to (38,100)

Nature of an Object Identity Item2=&Item1; Identity of original item2 is lost Storage needs to be reclaimed by GC If program is long-running program, it results in Memory Leak

Nature of an Object Identity Assignment Copy Vs. Aliasing (using pointer) Passing object pointer as parameter is efficient compare to passing entire object copy Equality Two objects are having same states Two object share same state When pointer to object is assigned to another pointer to object

Nature of an Object Identity Object Life Span The lifetime of an object extends from the time it is first created (and thus first consumes space) until that space is reclaimed . To explicitly create an object, we must either declare it (stack) or allocate it (heap).

Nature of an Object Identity Object Life Span Value (Stack) vs. Reference (Heap) Allocation & De-allocation (new & delete in C++) Garbage Collection A process that reclaims memory allocated to object when no reference to object exist. Destroy calls destructor Persistent Object (stored on disk, remains live even after program execution is over)

Relationships Among Objects An object by itself is intensely uninteresting. Objects contribute to the behavior of a system by collaborating with one another

Relationships Among Objects Kinds of Relationships 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. Two kinds of object hierarchies are: Links (also called seniority) Aggregation (also called parent/child relationships)

Relationships Among Objects Links The link is a physical or conceptual connection between objects A link denotes the specific association through which one object (the client) applies (request) the services of another object (the supplier)

Relationships Among Objects Links Message passing between two objects is typically unidirectional, although it may occasionally be bidirectional Notice also that although message passing is initiated by the client and is directed toward the supplier, data may flow in either direction across a link.

Relationships Among Objects Links As a participant in a link, an object may play one of three roles: Actor (Controller) An object that can operate upon other objects but is never operated upon by other objects; in some contexts, the terms active object and actor are interchangeable Server An object that never operates upon other objects; it is only operated upon by other objects Agent (Proxy) An object that can both operate upon other objects and be operated upon by other objects; an agent is usually created to do some work on behalf of an actor or another agent

Relationships Among Objects Links Flow Controller – Controller/Actor Display Panel – Server Valve – Proxy/Agent

Relationships Among Objects Links Visibility Consider two objects, A and B, with a link between the two. In order for A to send a message to B, B must be visible to A in some manner.

Relationships Among Objects Links There are four different ways that one object may have visibility to another: The supplier object is global (within the same scope or public) to the client. The supplier object is a parameter to some operation of the client. The supplier object is a part of the client object. The supplier object is a locally declared object in some operation of the client.

Relationships Among Objects Links Synchronization Whenever one object passes a message to another across a link, the two objects are said to be synchronized. synchronization is usually accomplished by simple method invocation However, in the presence of multiple threads of control (concurrency), objects require more sophisticated message passing

Relationships Among Objects Links when one active object has a link to a passive one, we must choose one of three approaches to synchronization Sequential The semantics of the passive object are guaranteed only in the presence of a single active object at a time. Guarded The semantics of the passive object are guaranteed in the presence of multiple threads of control, but the active clients must collaborate to achieve mutual exclusion. Synchronous The semantics of the passive object are guaranteed in the presence of multiple threads of control, and the supplier guarantees mutual exclusion

Relationships Among Objects Aggregation Whereas links denote peer-to-peer or client/supplier relationships, aggregation denotes a whole/part hierarchy, with the ability to navigate from the whole (also called the aggregate) to its parts (also known as its attributes). In this sense, aggregation is a specialized kind of association.

Relationships Among Objects Aggregation Example ClassA ObjectA { …; ClassB ObjectB; …} The ObjectB is a part of the state of the ObjectA Given the object ObjectA, it is possible to find its corresponding ObjectB. Given an object such as ObjectB, it is possible to navigate to its enclosing object ObjetcA (also called its container) if and only if this knowledge is a part of the state of ObjectB.

Relationships Among Objects Aggregation Aggregation may or may not denote physical containment. For example, an airplane is composed of wings, engines, landing gear, and so on: this is a case of physical containment. On the other hand, the relationship between a shareholder and her shares is an aggregation relationship that does not require physical containment Shareholder owns Shares, but shares are not physical part of the shareholder

Relationships Among Objects Aggregation There are clear trade-offs between links and aggregation. Aggregation is sometimes better because it encapsulates parts as secrets of the whole. Links are sometimes better because they permit looser coupling among objects.

Relationships Among Objects Aggregation By implication, an object that is an attribute of another has a link to its aggregate Across this link, the aggregate may send messages to its parts

Relationships Among Objects Aggregation

Unit-2 is Achieved