Fundamentals of Object Orientedtechnology - Classes and Objects
Fundamentals of Object Orientedtechnology - Classes and Objects
OrientedTechnology
- Classes and Objects
1. Objects
2. Classes
3. Visibility
4. Polymorphism
Objects
• Conceptual entity
• Software entity
Objects
• What is an Object?
• Informally, an object
represents an entity,
either physical,
conceptual, or software
• Physical entity
• Software entity
A More Formal Definition
• An object has a state,behaviour and
identity,the structure and behaviour of
similar objects are defined in their common
class;
• An object is something that has
• State
• Behavior
• Identity
Object
• State: encompasses all of the properties of
the object (usually static)+ the current
values of each of these properties (usually
dynamic)
• Behavior: how an object acts and reacts, in
terms of its state changes and message
passing.
• Identity: property of an object which
distinguishes it from all other objects.
State
• The state of an object encompasses all of
the properties of the object plus the current
values of each of these properties.
• Examples includes the following.
Vending machine
State
• The state of an object is one of the possible
conditions in which an object may exist
• The state of an object normally changes
over time
State
• low-level definition:
• 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.
OBJECTS
• Consider the structure of a personnel record. In C+
+ we might write:
struct PersonnelRecord
{
char name[100];
int socialSecurity_Number;
char department[10];
float salary;
}
Behavior
• No object exists in isolation .
• Objects are acted upon and themselves act
upon other objects.
• Behavior is how an object acts and reacts, in
terms of its state changes and message
passing.
• The state of an object represents the
cumulative results of its behavior.
Behavior
• An Object Has Behavior
• Behavior determines how an
object acts and reacts to
requests from other objects
• Behavior is represented by the
set of messages it can respond
to (the operations the object
can perform)
Assign Y.Welikala
(Returns: conformation)
Category Relationship
Linear one one
Hierarchical one many
Graph many many
Sets none none
Associations
One-to-one relationship between elements
• Each element has unique predecessor
• Each element has unique successor
Examples of association
• List
Collection of elements in order
• Queue
Elements removed in order of insertion
First-in, First-out (FIFO)
Associations
• One-to-many relationship between elements
Each element has unique predecessor
Each element has multiple successors
Example One to many
• Tree
Single root
Association- example
• Many-to-many relationship between elements
Each element has multiple predecessors
Each element has multiple successors
Inheritance
• Single inheritance(“is a”):
• Classes with no instances are called
abstract classes.
• A class has 2 kinds of clients
• Instances
• Subclasses.
• Multiple inheritance
• Polymorphism
• Superclass-subclass-
Aggregation
Aggregation:
• Part-of relationship
• In this objects representing the components of something are
associated with an object representing the entire assembly.
• .
• Aggregation is a specialize form of Association where all object
have their own lifecycle but there is ownership ,and child object can
not belongs to another parent object. Let’s take an example of
Department and teacher. A single teacher can not belongs to multiple
departments, but if we delete the department teacher object will not
destroy. We can think about “has-a” relationship.
Using
• Using relationship is one possible refinement of an
association, where by we assert which abstraction is the
client and which is the supplier of certain services.
• Strict “using "relationships are occasionally too confining
because they allow the client access only to the public
interface of the supplier.
• One class may use another in a variety of ways., Here
Temperature controller will use temperature ramp in the
signature of its interface
metaclass
• A class of the class is known as metaclass.
• A metaclass is a class whose instances are
themselves classes.
• In languages such as smalltalk,the primary
purpose of a metaclass is to provide class
variables.,which are shared by all instances of the
class and operations for initializing class
variables
• C++ doesnot explicitly support metaclasses,its
constructor and destructor semantics serve the
purpose of metaclass creation operations.
3.5 The Interplay of Classes and
Objects
Relationships between classes and objects