11-20 Ooad Mid-1
11-20 Ooad Mid-1
The object model visualizes the elements in a software application in terms of objects. In this chapter,
we will look into the basic concepts and terminologies of object–oriented systems.
The concepts of objects and classes are intrinsically linked with each other and form the foundation of
object–oriented paradigm.
Object
• State that determines the characteristic properties of an object as well as the values of the
properties that the object holds.
• Behavior that represents externally visible activities performed by an object in terms of changes
in its state.
Objects can be modelled according to the needs of the application. An object may have a physical
existence, like a customer, a car, etc.; or an intangible conceptual existence, like a project, a process, etc.
Class
A class represents a collection of objects having same characteristic properties that exhibit common
behavior. It gives the blueprint or description of the objects that can be created from it. Creation of an
object as a member of a class is called instantiation. Thus, object is an instance of a class.
• A set of attributes for the objects that are to be instantiated from the class. Generally, different
objects of a class have some difference in the values of the attributes. Attributes are often
referred as class data.
• A set of operations that portray the behavior of the objects of the class. Operations are also
referred as functions or methods.
Example
Let us consider a simple class, Circle, that represents the geometrical figure circle in a two–dimensional
space. The attributes of this class can be identified as follows −
During instantiation, values are assigned for at least some of the attributes. If we create an object
my_circle, we can assign values like x-coord : 2, y-coord : 3, and a : 4 to depict its state. Now, if the
operation scale() is performed on my_circle with a scaling factor of 2, the value of the variable a will
become 8. This operation brings a change in the state of my_circle, i.e., the object has exhibited certain
behavior.
Encapsulation
Encapsulation is the process of binding both attributes and methods together within a class. Through
encapsulation, the internal details of a class can be hidden from outside. It permits the elements of the
class to be accessed from outside only through the interface provided by the class.
Data Hiding
Typically, a class is designed such that its data (attributes) can be accessed only by its class methods and
insulated from direct outside access. This process of insulating an object’s data is called data hiding or
information hiding.
Example
In the class Circle, data hiding can be incorporated by making attributes invisible from outside the class
and adding two more methods to the class for accessing class data, namely −
Here the private data of the object my_circle cannot be accessed directly by any method that is not
encapsulated within the class Circle. It should instead be accessed through the methods setValues() and
getValues().
Explore our latest online courses and learn new skills at your own pace. Enroll and become a certified
expert to boost your career.
Message Passing
Any application requires a number of objects interacting in a harmonious manner. Objects in a system
may communicate with each other using message passing. Suppose a system has two objects: obj1 and
obj2. The object obj1 sends a message to object obj2, if obj1 wants obj2 to execute one of its methods.
Inheritance
Inheritance is the mechanism that permits new classes to be created out of existing classes by extending
and refining its capabilities. The existing classes are called the base classes/parent classes/super-classes,
and the new classes are called the derived classes/child classes/subclasses. The subclass can inherit or
derive the attributes and methods of the super-class(es) provided that the super-class allows so. Besides,
the subclass may add its own attributes and methods and may modify any of the super-class methods.
Inheritance defines an “is – a” relationship.
Example
From a class Mammal, a number of classes can be derived such as Human, Cat, Dog, Cow, etc. Humans,
cats, dogs, and cows all have the distinct characteristics of mammals. In addition, each has its own
particular characteristics. It can be said that a cow “is – a” mammal.
Types of Inheritance
• Multilevel Inheritance − A subclass derives from a super-class which in turn is derived from
another class and so on.
• Hierarchical Inheritance − A class has a number of subclasses each of which may have
subsequent subclasses, continuing for a number of levels, so as to form a tree structure.
Polymorphism is originally a Greek word that means the ability to take multiple forms. In object-oriented
paradigm, polymorphism implies using operations in different ways, depending upon the instance they
are operating upon. Polymorphism allows objects with different internal structures to have a common
external interface. Polymorphism is particularly effective while implementing inheritance.
Example
Let us consider two classes, Circle and Square, each with a method findArea(). Though the name and
purpose of the methods in the classes are same, the internal implementation, i.e., the procedure of
calculating area is different for each class. When an object of class Circle invokes its findArea() method,
the operation finds the area of the circle without any conflict with the findArea() method of the Square
class.
Generalization
In the generalization process, the common characteristics of classes are combined to form a class in a
higher level of hierarchy, i.e., subclasses are combined to form a generalized super-class. It represents an
“is – a – kind – of” relationship. For example, “car is a kind of land vehicle”, or “ship is a kind of water
vehicle”.
Specialization
Specialization is the reverse process of generalization. Here, the distinguishing features of groups of
objects are used to form specialized classes from existing classes. It can be said that the subclasses are
the specialized versions of the super-class.
Link
A link represents a connection through which an object collaborates with other objects. Rumbaugh has
defined it as “a physical or conceptual connection between objects”. Through a link, one object may
invoke the methods or navigate through another object. A link depicts the relationship between two or
more objects.
Association
Association is a group of links having common structure and common behavior. Association depicts the
relationship between objects of one or more classes. A link can be defined as an instance of an
association.
Degree of an Association
Degree of an association denotes the number of classes involved in a connection. Degree may be unary,
binary, or ternary.
Cardinality of a binary association denotes the number of instances participating in an association. There
are three types of cardinality ratios, namely −
• Many–to–Many − An object of class A may be associated with many objects of class B and
conversely an object of class B may be associated with many objects of class A.
Aggregation or Composition
Aggregation or composition is a relationship among classes by which a class can be made up of any
combination of objects of other classes. It allows objects to be placed directly within the body of other
classes. Aggregation is referred as a “part–of” or “has–a” relationship, with the ability to navigate from
the whole to its parts. An aggregate object is an object that is composed of one or more other objects.
Example
In the relationship, “a car has–a motor”, car is the whole object or the aggregate, and the motor is a
“part–of” the car. Aggregation may denote −
Now that we have gone through the core concepts pertaining to object orientation, it would be
worthwhile to note the advantages that this model has to offer.
The quality of an abstraction can be evaluated using various criteria that assess its effectiveness, clarity,
and utility. A good abstraction simplifies complex systems, promotes understanding, and reduces
cognitive load without sacrificing essential details. Below are key metrics and factors to consider when
measuring the quality of an abstraction:
1. Simplicity
• Definition: The abstraction should reduce complexity by focusing on essential details and hiding
unnecessary implementation details.
• Measurement:
o Does the abstraction reduce the mental effort required to understand and use it?
2. Generalization
• Definition: A good abstraction should apply to a broad range of scenarios while remaining
specific enough to solve a problem effectively.
• Measurement:
3. Consistency
• Definition: The abstraction should behave predictably and adhere to established principles,
patterns, or conventions.
• Measurement:
o Does the abstraction align with the user's expectations and domain-specific standards?
4. Completeness
• Definition: The abstraction should fully address the problem it is meant to solve without
requiring the user to deal with hidden complexities.
• Measurement:
o Does the abstraction provide all the necessary tools and information for its intended
purpose?
o Does it leave out critical details that users must work around?
5. Clarity
• Measurement:
o Can users grasp its purpose and usage with minimal effort?
6. Encapsulation
• Definition: The abstraction should effectively encapsulate underlying details to protect users
from dealing with lower-level complexities.
• Measurement:
o Are the internal workings hidden while exposing only what is necessary?
7. Minimalism
• Definition: A good abstraction avoids unnecessary features or components, which can make it
bloated or harder to use.
• Measurement:
o Does the abstraction include only the features needed for its purpose?
o Are there any elements that could be removed without affecting functionality?
• Measurement:
9. Performance
• Definition: While hiding complexity, the abstraction should not impose significant performance
overhead.
• Measurement:
o Does the abstraction introduce inefficiencies that could have been avoided?
• Definition: The abstraction should provide clear mechanisms for handling errors or unexpected
conditions.
• Measurement:
o Does the abstraction make it easy to detect, handle, and recover from errors?
11. Orthogonality
• Definition: Each component of the abstraction should serve a distinct purpose without
overlapping responsibilities.
• Measurement:
Examples:
• In data science, a well-crafted data model is a good abstraction when it represents complex
relationships while being easy to query and extend.
13. Discuss clearly about different Models of Object-Oriented Development with a neat sketch?
Object-Oriented Development (OOD) involves using object-oriented principles to design and build
software. The process is typically organized into several models, each representing a different aspect of
the system under development. These models help in analyzing, designing, and implementing object-
oriented systems systematically. Below is a discussion of the different models used in OOD, along with a
sketch to illustrate their relationships.
1. Object Model
• Purpose: Describes the static structure of the system, focusing on objects, their attributes,
operations, and relationships.
• Key Elements:
o Relationships:
2. Dynamic Model
• Purpose: Captures the dynamic behavior of objects and their interactions over time.
• Key Elements:
o State Diagrams: Show how objects transition between states based on events.
3. Functional Model
• Purpose: Represents the functional aspects of the system, focusing on what the system does
rather than how it behaves.
• Key Elements:
o Data Flow Diagrams (DFDs): Depict the flow of data between functions.
o Use Case Diagrams: Show interactions between actors and the system.
• Output: Use case diagrams, DFDs, and textual use case descriptions.
4. Implementation Model
• Purpose: Translates the design into code and defines how objects and components are
implemented in the chosen programming language.
• Key Elements:
5. Deployment Model
• Purpose: Describes the physical deployment of the system, showing how software components
map to hardware nodes.
• Key Elements:
2. The Dynamic Model adds behavior (object interactions and state changes).
3. The Functional Model emphasizes what the system does (functional requirements).
5. The Deployment Model ensures the system operates as intended in its physical environment.
14. How does one properly identify the classes and objects that are relevant to a particular application?
Explain?
An Object Diagram in OOAD is used to represent a snapshot of the system at a particular moment in
time, showing specific instances of classes (objects) and their relationships. Unlike class diagrams, which
define the structure of the system in terms of types, object diagrams illustrate the state of the system
with actual objects and their links, providing a more concrete view of how classes are instantiated and
related.
Key Modeling Techniques for Object Diagrams
Below are various modeling techniques and best practices for creating object diagrams:
● Naming: Objects in an object diagram are named as instances of a class, typically with the form
objectName: ClassName. For example, john: Person represents an instance john of the class Person.
● For each object, show the values of the attributes at a particular point in time. These
attribute values provide a snapshot of the object's state.
○ age=30 ○ balance=500.75
Roles: If necessary, you can label the links with role names to clarify the nature of the relationship.
For example, customer1 -(purchases) --> order1.
● In some object diagrams, you can include the state of the object at a particular moment by
showing certain attributes' values. For example, in a shopping cart scenario, you may want to show
the state of an
○ orderStatus="Pending"
○ totalAmount=150.00
● In object diagrams, the class names of the objects are usually written in a different
font style (italicized) or placed in a compartment at the top of the object box.
● For example, an object order1: Order will have the name Order in italics or in the top
section of the object box, and order1 is the specific instance.
Object diagrams typically focus on concrete instances rather than abstract objects or classes.
Abstract classes and their instances should be clearly represented as instances of concrete
subclasses.
● Temporal Aspect: You can indicate the lifetime of objects by showing when an object comes into
existence and when it is destroyed, particularly in sequence or communication diagrams, but not
explicitly in an object diagram. However, it’s sometimes implied by the context and how objects
interact.
● Object diagrams are often useful in debugging or for visualizing test cases. If you're analyzing a
scenario, you can show objects in their current state, helping to debug issues related to object
interactions.
● For instance, if a Car has a composition relationship with Wheel (i.e., the car has
wheels, and if the car is destroyed, so are the wheels), the object diagram will show
instances of Car and Wheel connected by a solid diamond.
● Object diagrams can represent multiple instances of the same class. In this case, you can show
multiple objects of the same class (e.g., several Employee objects with different attribute values).
Object diagrams are often used in scenario-based modeling, where they can represent particular
states of a system during the execution of a use case.
● A scenario might be represented as an object diagram where different objects are instantiated with
various values and links representing the interaction between those objects during a particular flow
of the system.
a Class Diagram represents the static structure of a system by showing its classes, their attributes,
operations, and the relationships between the objects. Modelling a class diagram effectively involves
using a variety of techniques and best practices to ensure the diagram is clear, understandable, and
reflective of the system's architecture.
1. Identify Classes
● Identify the key objects in the system and group them as classes.
These might correspond to real-world entities (e.g., Person, Car, Order), system components (e.g.,
Controller, Database), or abstract concepts (e.g., Transaction, Workflow).
2. Define Attributes
● For each class, define its attributes. These are the properties or fields that describe
the class. For example, a Person class may have attributes like name, age, and address.
● Include the visibility of attributes (public, private, protected), typically using the
following notation:
3. Define Methods/Operations
● Identify the functions or methods (operations) that the class will perform. For
example, the Person class might have methods like getFullName(), updateAddress(), etc.
● Similarly to attributes, methods should be defined with visibility, return types, and
parameters. For example:
○ +calculateSalary() : double
○ -setPassword(newPassword: String)
4. Define Relationships
● Association: Use solid lines to indicate associations between classes, with or without
arrowheads, depending on the direction of the relationship. An association shows that one
class is related to another but doesn’t imply ownership.
● Composition: A stronger form of aggregation, indicating that the part cannot exist
without the whole. This is represented by a filled diamond. For example, a House class could
have a Room class in a composition relationship, meaning if a house is destroyed, the rooms
are also destroyed.
● Inheritance (Generalization): Use a line with a hollow triangle at the base to indicate
inheritance. For example, a Dog class can inherit from an Animal class. This signifies that Dog
is a specialized type of Animal.
○ Example: Dog inherits from Animal, so Dog will inherit attributes and
methods of Animal.
● Realization: Represented with a dashed line and a hollow triangle, realization is used
to show that a class implements an interface. For instance, Car might implement the Vehicle
interface.
5. Use of Interfaces
● Interfaces: An interface defines a contract that classes can implement. In the class diagram, you
can represent interfaces with a «interface» stereotype, and the implementing classes with a solid
line from the class to the interface, typically with a dashed arrow or line with the implements
keyword.
○ Example: A Vehicle interface with start() and stop() methods could be implemented by Car and
Bike.
● Use abstract methods to indicate methods that don’t have implementations in the
abstract class but must be implemented in subclasses.
7. Use Stereotypes
<<boundary>>, <<interface>>
○ Example: For a Factory Method Pattern, you can represent the interface with a method to create
objects, and the concrete classes implementing this factory.
● For Composite Pattern, use a class diagram to show that a Composite class contains
both Leaf and Composite objects,
● Add OCL (Object Constraint Language) or textual constraints to represent business rules and
restrictions, such as "A customer can only have one address at a time" or "A Person can have only
one Passport".
● Use Packages to group related classes. This is especially helpful in large systems to show the
modularity and organization of classes. Each package can be represented as a folder icon, and you
can draw dependencies between packages.
● Keep your diagrams simple and avoid overcrowding. If your system has many classes
or relationships, break it down into smaller, manageable sub-diagrams.
● Layering: You can use layers or separate diagrams for different levels of the system,
like domain logic, data access, or presentation layers.
Modeling is a fundamental aspect of software engineering and system design, allowing us to abstract
and represent complex systems in a simplified, understandable form. Here are the four basic
principles of modeling explained in detail:
1. Abstraction
• Definition: Abstraction involves focusing on the essential aspects of a system while ignoring
irrelevant details.
• Key Idea: Models should capture only what is necessary for the specific problem or
audience.
• Example:
o In a library system, instead of modeling every physical detail of a book (e.g., size,
weight, color), the abstraction focuses on attributes like title, author, and ISBN,
which are relevant to library operations.
• Importance:
2. Accuracy
• Purpose: To ensure the model is useful for decision-making and does not mislead
stakeholders.
• Key Idea: The model must be an accurate reflection of reality or the desired system behavior
within the chosen level of abstraction.
• Example:
o A model of a car's engine must accurately represent the flow of fuel and energy,
even if it omits details like color or surface finish.
• Importance:
3. Understandability
• Key Idea: The complexity of the model should match the expertise and needs of the
audience.
• Example:
• Importance:
• Purpose: To save time and effort in future projects by leveraging existing models or
components.
• Key Idea: Models should be generalized enough to apply to multiple situations without
significant rework.
• Example:
• Importance:
18. What is a nature of Class and Object? How to identify Classes and Objects with suitable
Examples?
Class:
• A class is a blueprint or template used to define objects. It encapsulates data (attributes) and
behaviors (methods) that describe a particular type of entity in the problem domain.
• It is abstract, meaning it provides the structure but doesn't represent a specific instance.
• Nature of a Class:
o Relationships: Classes may interact with other classes (e.g., inheritance, association).
Object:
• Objects are concrete, meaning they hold specific values for the attributes defined by the
class.
• Nature of an Object:
o Study the requirements, use cases, or user stories to understand the system.
3. Categorize Candidates:
4. Define Relationships:
o Identify inheritance hierarchies (e.g., "Admin and Customer are types of Users").
o Simulate how the identified classes and objects interact in real-world scenarios to
ensure completeness.
• Requirement: "A member can borrow books from the library. Each book has a title, author,
and ISBN. Borrowing details are recorded."
• Steps:
o Nouns (Classes):
o Attributes:
o Methods:
▪ Book: checkAvailability().
• Objects: A specific member ("John Doe"), a specific book ("The Great Gatsby"), and a specific
borrowing record.
• Requirement: "A customer can browse products, add them to a cart, and place an order."
• Steps:
o Nouns (Classes):
o Attributes:
o Methods:
• Objects:
o Customer: A specific customer ("Jane Smith").
The collaboration diagram is used to show the relationship between the objects in a system. Both the
sequence and the collaboration diagrams represent the same information but differently. Instead of
showing the flow of messages, it depicts the architecture of the object residing in the system as it is
based on object-oriented programming. An object consists of several features. Multiple objects
present in the system are connected to each other. The collaboration diagram, which is also known
as a communication diagram, is used to portray the object's architecture in the system.
Following are the components of a component diagram that are enlisted below:
1. Objects: The representation of an object is done by an object symbol with its name
and class underlined, separated by a colon.
In the collaboration diagram, objects are utilized in the following ways: o The object is represented
by specifying their name and class. o It is not mandatory for every class to appear. o A class may
constitute more than one object.
o In the collaboration diagram, firstly, the object is created, and then its class is specified. o To
differentiate one object from another object, it is necessary to name them.
2. Actors: In the collaboration diagram, the actor plays the main role as it invokes the
interaction. Each actor has its respective role and name. In this, one actor initiates the use
case.
3. Links: The link is an instance of association, which associates the objects and actors.
It portrays a relationship between the objects through which the messages are sent. It is
represented by a solid line. The link helps an object to connect with or navigate to another
object, such that the message flows are attached to links.
The collaborations are used when it is essential to depict the relationship between the object. Both
the sequence and collaboration diagrams represent the same information, but the way of portraying
it quite different. The collaboration diagrams are best suited for analyzing use cases.
Following are some of the use cases enlisted below for which the collaboration diagram is
implemented:
1. To model collaboration among the objects or roles that carry the functionalities of
use cases and operations.
3. To capture the interactions that represent the flow of messages between the objects
and the roles inside the collaboration.
1. Determine the behavior for which the realization and implementation are specified.
2. Discover the structural elements that are class roles, objects, and subsystems for
performing the functionality of collaboration.
o Choose the context of an interaction: system, subsystem, use case, and operation.
o A specification level diagram may be made in the instance level sequence diagram
for summarizing alternative situations.
2. It mainly puts emphasis on the structural aspect of an interaction diagram, i.e., how
lifelines are connected.
3. The syntax of a collaboration diagram is similar to the sequence diagram; just the
difference is that the lifeline does not consist of tails.
7. It focuses on the elements and not the message flow, like sequence diagrams.
8. Since the collaboration diagrams are not that expensive, the sequence diagram can
be directly converted to the collaboration diagram.