Objects The ability to recognize the physical objects is a skill humans possess. We understand that an object is a tangible entity that exhibits some well-defined behavior. An object can be any of the following: 1. A tangible and/or visible thing. 2. Something towards which our thought or action is directed. 3. Something that may be understood intellectually.
Real-world objects are not the only kind of objects that are of interest to us in SW development. Other important kinds of objects are inventions of the Design process whose collaboration with other such objects to provide some high-level behavior or functionality.
An object represents an individual, identifiable item, unit, or entity either in the real world or abstract, with a well-defined role in the problem domain.
An object is anything that has crisply defined boundary.
Speed, color, temp etc. can not become objects. These
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.
State of an object The state of an object encompasses all the properties (usually static) of an object plus the current (usually dynamic) values of each of these properties.
All properties have values- simple or another object.
Every object has a state implies that every object takes
up some amount of space, be it in the real world, or in the computer memory.
Behavior of an object Objects dont stay in isolation. They keep interacting with each other. They act upon others and similarly are acted upon by other objects.
Behavior is how an object acts and reacts, in terms of
its state changes and message passing.
Behavior of an object represents its outwardly
visible activity. Prof.R.Gururaj Object Oriented Programming BITS Pilani, Hyderabad Campus We use the terms operation and message interchangeably.
Some operations may change the state of an object and
some may not. The operations that clients may perform upon an object are generally declared as methods.
An operation denotes a service that a class offers to its clients. Modifier - an operation that alters the state. Selector - to access the state of an object. Iterator - to access parts of an object in a well defined way. Constructor- Destructor -
Roles and Responsibilities The methods of an object comprise its protocol. It is useful to divide this large protocol into logical groupings. Each partition denotes a role it can play. Each role has some responsibilities.
Objects as machines Object has state. Hence it can behave like a machine. In many cases we can characterize the behavior of an object using finite state machine. Active Object owns execution control, autonomous Passive object-
Multiple Active classes means multiple Threads of control.
Parameter passing. Call by Value and call by reference. Object lifetime: It lives from the time it is created (using new operator) until its space is reclaimed. Memory leak: Persistent objects: transcend the lifetime of the program that created it.
Relationships among Objects Objects contribute to the behavior of the system by collaborating with one another. Link: Physical or conceptual connection between two objects. A link denotes the specific association between objects. Through this an object applies for a service of another object. As a participant in a link, an object may play following roles- Actor; Server; Agent
Aggregation Links denote peer-to-peer or client/server relationships. Aggregation denotes a whole-part hierarchy. In the sense it is a specialized kind of association. This could be physical or conceptual. Ex: Desks are part of ClassRoom. (physical) A graduate program has courses (conceptual).
Aggregation Aggregation encapsulates parts as secrets of whole. Links enable looser coupling among objects. An object that is part of another has a link to aggregate. Aggregate can send a message to part through this link.
Class A class represents a set of objects that share a common structure and a common behavior. A single object is an instance of a class. An individual object is a concrete entity that performs some role in the overall system. The class captures the structure and behavior common to all related objects.
Class The interface of a class provides its outside view and therefore helps in hiding the structure and secrets of behavior. By contrast the implementation of a class is its inside view, which encompasses the secrets of its behavior. Types of interfaces: Public ; Private; Protected
Criteria to be considered for making decisions on operations
Reusability Complexity Applicability (is the behavior relevant to the type or not). Implementation knowledge (does implementation depend on the internal details of type?)
Summary Object - state, identity, and behavior Active/passive objects Parameter passing Types of operations Link and Aggregation Class Relationships Quality of abstraction Criteria for operations