SlideShare ist ein Scribd-Unternehmen logo
1 von 52
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
• 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
• 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
• 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

Weitere ähnliche Inhalte

Ähnlich wie Objects and Classes.pptx

[OOP - Lec 04,05] Basic Building Blocks of OOP
[OOP - Lec 04,05] Basic Building Blocks of OOP[OOP - Lec 04,05] Basic Building Blocks of OOP
[OOP - Lec 04,05] Basic Building Blocks of OOPMuhammad Hammad Waseem
 
Design Pattern lecture 4
Design Pattern lecture 4Design Pattern lecture 4
Design Pattern lecture 4Julie Iskander
 
Lukito Edi Nugroho - Object Orientation Concepts
Lukito Edi Nugroho - Object Orientation ConceptsLukito Edi Nugroho - Object Orientation Concepts
Lukito Edi Nugroho - Object Orientation Conceptsbelajarkomputer
 
Object Modelling Technique " ooad "
Object Modelling Technique  " ooad "Object Modelling Technique  " ooad "
Object Modelling Technique " ooad "AchrafJbr
 
Structural modeling and analysis
Structural modeling and analysisStructural modeling and analysis
Structural modeling and analysisJIGAR MAKHIJA
 
Handout on Object orienetd Analysis and Design
Handout on Object orienetd Analysis and DesignHandout on Object orienetd Analysis and Design
Handout on Object orienetd Analysis and DesignSAFAD ISMAIL
 
Object Oriented Programming Tutorial.pptx
Object Oriented Programming Tutorial.pptxObject Oriented Programming Tutorial.pptx
Object Oriented Programming Tutorial.pptxethiouniverse
 
Intro to oop.pptx
Intro to oop.pptxIntro to oop.pptx
Intro to oop.pptxUmerUmer25
 
Basic concepts of object oriented programming
Basic concepts of object oriented programmingBasic concepts of object oriented programming
Basic concepts of object oriented programmingSachin Sharma
 
Object oriented programming 6 oop with c++
Object oriented programming 6  oop with c++Object oriented programming 6  oop with c++
Object oriented programming 6 oop with c++Vaibhav Khanna
 
IBM OOAD Part1 Summary
IBM OOAD Part1 SummaryIBM OOAD Part1 Summary
IBM OOAD Part1 SummaryHaitham Raik
 

Ähnlich wie Objects and Classes.pptx (20)

[OOP - Lec 04,05] Basic Building Blocks of OOP
[OOP - Lec 04,05] Basic Building Blocks of OOP[OOP - Lec 04,05] Basic Building Blocks of OOP
[OOP - Lec 04,05] Basic Building Blocks of OOP
 
Design Pattern lecture 4
Design Pattern lecture 4Design Pattern lecture 4
Design Pattern lecture 4
 
Object oriented programming
Object oriented programmingObject oriented programming
Object oriented programming
 
Lukito Edi Nugroho - Object Orientation Concepts
Lukito Edi Nugroho - Object Orientation ConceptsLukito Edi Nugroho - Object Orientation Concepts
Lukito Edi Nugroho - Object Orientation Concepts
 
O6u CS-315A OOP Lecture (1).pdf
O6u CS-315A OOP Lecture (1).pdfO6u CS-315A OOP Lecture (1).pdf
O6u CS-315A OOP Lecture (1).pdf
 
C# by Zaheer Abbas Aghani
C# by Zaheer Abbas AghaniC# by Zaheer Abbas Aghani
C# by Zaheer Abbas Aghani
 
C# by Zaheer Abbas Aghani
C# by Zaheer Abbas AghaniC# by Zaheer Abbas Aghani
C# by Zaheer Abbas Aghani
 
Object Modelling Technique " ooad "
Object Modelling Technique  " ooad "Object Modelling Technique  " ooad "
Object Modelling Technique " ooad "
 
Structural modeling and analysis
Structural modeling and analysisStructural modeling and analysis
Structural modeling and analysis
 
Handout on Object orienetd Analysis and Design
Handout on Object orienetd Analysis and DesignHandout on Object orienetd Analysis and Design
Handout on Object orienetd Analysis and Design
 
Object Oriented Programming Tutorial.pptx
Object Oriented Programming Tutorial.pptxObject Oriented Programming Tutorial.pptx
Object Oriented Programming Tutorial.pptx
 
Ooad unit – 1 introduction
Ooad unit – 1 introductionOoad unit – 1 introduction
Ooad unit – 1 introduction
 
Introduction
IntroductionIntroduction
Introduction
 
[OOP - Lec 06] Classes and Objects
[OOP - Lec 06] Classes and Objects[OOP - Lec 06] Classes and Objects
[OOP - Lec 06] Classes and Objects
 
Object modeling
Object modelingObject modeling
Object modeling
 
Intro to oop.pptx
Intro to oop.pptxIntro to oop.pptx
Intro to oop.pptx
 
Basic concepts of object oriented programming
Basic concepts of object oriented programmingBasic concepts of object oriented programming
Basic concepts of object oriented programming
 
OOPS in Java
OOPS in JavaOOPS in Java
OOPS in Java
 
Object oriented programming 6 oop with c++
Object oriented programming 6  oop with c++Object oriented programming 6  oop with c++
Object oriented programming 6 oop with c++
 
IBM OOAD Part1 Summary
IBM OOAD Part1 SummaryIBM OOAD Part1 Summary
IBM OOAD Part1 Summary
 

Mehr von BalasundaramSr

Mehr von BalasundaramSr (20)

WEB 3 IS THE FILE UPLOADED IN THIS APPROACH
WEB 3 IS THE FILE UPLOADED IN THIS APPROACHWEB 3 IS THE FILE UPLOADED IN THIS APPROACH
WEB 3 IS THE FILE UPLOADED IN THIS APPROACH
 
Semantic Search to Web 3.0 Complete Tutorial
Semantic Search to Web 3.0 Complete TutorialSemantic Search to Web 3.0 Complete Tutorial
Semantic Search to Web 3.0 Complete Tutorial
 
Objects and Classes BRIEF.pptx
Objects and Classes BRIEF.pptxObjects and Classes BRIEF.pptx
Objects and Classes BRIEF.pptx
 
SocialCom09-tutorial.pdf
SocialCom09-tutorial.pdfSocialCom09-tutorial.pdf
SocialCom09-tutorial.pdf
 
13047926.ppt
13047926.ppt13047926.ppt
13047926.ppt
 
Xpath.pdf
Xpath.pdfXpath.pdf
Xpath.pdf
 
OSNs.pptx
OSNs.pptxOSNs.pptx
OSNs.pptx
 
HadoopIntroduction.pptx
HadoopIntroduction.pptxHadoopIntroduction.pptx
HadoopIntroduction.pptx
 
HadoopIntroduction.pptx
HadoopIntroduction.pptxHadoopIntroduction.pptx
HadoopIntroduction.pptx
 
Data Mart Lake Ware.pptx
Data Mart Lake Ware.pptxData Mart Lake Ware.pptx
Data Mart Lake Ware.pptx
 
Simple SNA.pdf
Simple SNA.pdfSimple SNA.pdf
Simple SNA.pdf
 
XPATH_XSLT-1.pptx
XPATH_XSLT-1.pptxXPATH_XSLT-1.pptx
XPATH_XSLT-1.pptx
 
Cognitive Science.ppt
Cognitive Science.pptCognitive Science.ppt
Cognitive Science.ppt
 
Web Page Design.ppt
Web Page Design.pptWeb Page Design.ppt
Web Page Design.ppt
 
wipo_res_dev_ge_09_www_130165.ppt
wipo_res_dev_ge_09_www_130165.pptwipo_res_dev_ge_09_www_130165.ppt
wipo_res_dev_ge_09_www_130165.ppt
 
OOA Analysis(1).pdf
OOA Analysis(1).pdfOOA Analysis(1).pdf
OOA Analysis(1).pdf
 
OODIAGRAMS.ppt
OODIAGRAMS.pptOODIAGRAMS.ppt
OODIAGRAMS.ppt
 
Threading.pptx
Threading.pptxThreading.pptx
Threading.pptx
 
OMTanalysis.ppt
OMTanalysis.pptOMTanalysis.ppt
OMTanalysis.ppt
 
network.ppt
network.pptnetwork.ppt
network.ppt
 

Kürzlich hochgeladen

SECOND SEMESTER TOPIC COVERAGE SY 2023-2024 Trends, Networks, and Critical Th...
SECOND SEMESTER TOPIC COVERAGE SY 2023-2024 Trends, Networks, and Critical Th...SECOND SEMESTER TOPIC COVERAGE SY 2023-2024 Trends, Networks, and Critical Th...
SECOND SEMESTER TOPIC COVERAGE SY 2023-2024 Trends, Networks, and Critical Th...KokoStevan
 
Mixin Classes in Odoo 17 How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17  How to Extend Models Using Mixin ClassesMixin Classes in Odoo 17  How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17 How to Extend Models Using Mixin ClassesCeline George
 
Class 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdfClass 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdfAyushMahapatra5
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxheathfieldcps1
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introductionMaksud Ahmed
 
Measures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDMeasures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDThiyagu K
 
Unit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptxUnit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptxVishalSingh1417
 
PROCESS RECORDING FORMAT.docx
PROCESS      RECORDING        FORMAT.docxPROCESS      RECORDING        FORMAT.docx
PROCESS RECORDING FORMAT.docxPoojaSen20
 
This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.christianmathematics
 
Web & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfWeb & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfJayanti Pande
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsTechSoup
 
Z Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphZ Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphThiyagu K
 
APM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAPM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAssociation for Project Management
 
Application orientated numerical on hev.ppt
Application orientated numerical on hev.pptApplication orientated numerical on hev.ppt
Application orientated numerical on hev.pptRamjanShidvankar
 
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxBasic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxDenish Jangid
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactPECB
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdfQucHHunhnh
 
Gardella_Mateo_IntellectualProperty.pdf.
Gardella_Mateo_IntellectualProperty.pdf.Gardella_Mateo_IntellectualProperty.pdf.
Gardella_Mateo_IntellectualProperty.pdf.MateoGardella
 
Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...
Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...
Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...Shubhangi Sonawane
 

Kürzlich hochgeladen (20)

SECOND SEMESTER TOPIC COVERAGE SY 2023-2024 Trends, Networks, and Critical Th...
SECOND SEMESTER TOPIC COVERAGE SY 2023-2024 Trends, Networks, and Critical Th...SECOND SEMESTER TOPIC COVERAGE SY 2023-2024 Trends, Networks, and Critical Th...
SECOND SEMESTER TOPIC COVERAGE SY 2023-2024 Trends, Networks, and Critical Th...
 
Mixin Classes in Odoo 17 How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17  How to Extend Models Using Mixin ClassesMixin Classes in Odoo 17  How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17 How to Extend Models Using Mixin Classes
 
Class 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdfClass 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdf
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptx
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introduction
 
Measures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDMeasures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SD
 
Unit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptxUnit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptx
 
PROCESS RECORDING FORMAT.docx
PROCESS      RECORDING        FORMAT.docxPROCESS      RECORDING        FORMAT.docx
PROCESS RECORDING FORMAT.docx
 
This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.
 
Web & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfWeb & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdf
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The Basics
 
Z Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphZ Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot Graph
 
APM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAPM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across Sectors
 
Application orientated numerical on hev.ppt
Application orientated numerical on hev.pptApplication orientated numerical on hev.ppt
Application orientated numerical on hev.ppt
 
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxBasic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global Impact
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
 
Advance Mobile Application Development class 07
Advance Mobile Application Development class 07Advance Mobile Application Development class 07
Advance Mobile Application Development class 07
 
Gardella_Mateo_IntellectualProperty.pdf.
Gardella_Mateo_IntellectualProperty.pdf.Gardella_Mateo_IntellectualProperty.pdf.
Gardella_Mateo_IntellectualProperty.pdf.
 
Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...
Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...
Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...
 

Objects and Classes.pptx

  • 2. Topics • Nature of an Object • Relationship among Objects • Nature of an Class • Relationship among Classes
  • 3. 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.
  • 4. 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
  • 5. 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.
  • 6. Nature of an Object State • 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.
  • 7. 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
  • 8. Nature of an Object State • Class Car • { – ModelName – Manufacture – CurrentGearNo – CurrentSpeed – HeadLightStatus • }
  • 9. 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.
  • 10. 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;
  • 11. 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
  • 12. 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; };
  • 13. 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
  • 14. 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.
  • 15. 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.
  • 16. 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.
  • 17. 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
  • 18. 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
  • 19. 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
  • 20. 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
  • 21. 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
  • 22. 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.
  • 23. 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
  • 24. 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.
  • 25. 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.
  • 26. 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.
  • 27. Nature of an Object Identity • Identity • Identity is that property of an object which distinguishes it from all other objects
  • 28. 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.
  • 29. 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.
  • 30. Nature of an Object Identity • DisplayItem item1; • DisplayItem *item2 = New DisplayItem(Point(75,75)); • DisplayItem *item3 = New DisplayItem(Point(100,100)); • DisplayItem *item4=0;
  • 31. Nature of an Object Identity • Item1 is changed from (0,0) to (75,75) • Item4=Item3 • Item4 is changed to (38,100)
  • 32. 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
  • 33. 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
  • 34. 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).
  • 35. 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)
  • 36. Relationships Among Objects • An object by itself is intensely uninteresting. • Objects contribute to the behavior of a system by collaborating with one another
  • 37. 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)
  • 38. 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)
  • 39. 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.
  • 40. 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
  • 41. Relationships Among Objects Links • Flow Controller – Controller/Actor • Display Panel – Server • Valve – Proxy/Agent
  • 42. 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.
  • 43. 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.
  • 44. 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
  • 45. 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
  • 46. Relationships Among Objects Aggregation • 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.
  • 47. 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.
  • 48. 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
  • 49. 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.
  • 50. 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