Notes OOSD Unit1,2 (1)
Notes OOSD Unit1,2 (1)
Unit1: Introduction: The meaning of Object Orientation, object identity, Encapsulation, information hiding,
polymorphism, generosity, importance of modelling, principles of modelling, object-oriented modelling,
Introduction to UML, conceptual model of the UML, Architecture.
Unit2: Basic Structural Modelling: Classes, Relationships, common Mechanisms, and diagrams. Class
&Object Diagrams: Terms, concepts, modelling techniques for Class & Object Diagrams.
Collaboration Diagrams: Terms, Concepts, depicting a message, polymorphism in collaboration Diagrams,
iterated messages, use of self in messages. Sequence Diagrams: Terms, concepts, depicting asynchronous
messages with/without priority, call-back mechanism, broadcast messages.
Basic Behavioural Modelling: Use cases, Use case Diagrams, Activity Diagrams, State Machine, Process and
thread, Event and signals, Time diagram, interaction diagram, Package diagram.
Architectural Modelling: Component, Deployment, Component diagrams and Deployment diagrams
UNIT1
Object Orientation (OO) is a programming paradigm based on the concept of "objects", which can contain data
and code. The primary characteristics of Object Orientation include:
2. Object Identity
Object Identity refers to the concept that each object has a unique identity that distinguishes it from other
objects, regardless of its state. Even if two objects have the same values for their attributes, they are still
different if they have different identities.
3. Encapsulation
Encapsulation is one of the fundamental principles of Object-Oriented Programming (OOP). It is the bundling
of data (attributes) and methods (behaviors) that operate on the data into a single unit or class. The internal
representation of an object is hidden from the outside world.
• Advantages:
o Protects object integrity by preventing outside interference.
o Simplifies the interface with which objects interact.
o Encourages modularity and maintenance.
• Example: A class Person may encapsulate data like name and age, along with methods like getName()
and setName() that control access to these variables.
4. Information Hiding
Information Hiding is closely related to encapsulation. It involves restricting access to certain parts of an
object to control how other objects interact with it. By hiding the internal details and only exposing what is
necessary, we increase security, reduce complexity, and ensure flexibility for future changes.
• Access Modifiers:
o Private: Accessible only within the class.
o Protected: Accessible within the class and by derived classes.
o Public: Accessible by any other class.
5. Polymorphism
Polymorphism allows objects of different classes to be treated as objects of a common superclass. It’s the
ability to process objects differently depending on their class or data type.
• Types of Polymorphism:
o Compile-time Polymorphism: Achieved through method overloading or operator overloading.
o Run-time Polymorphism: Achieved through method overriding (inherited methods are
redefined in the subclass).
• Example: A Shape class with a method draw(). Different subclasses like Circle and Rectangle
implement draw() differently.
6. Generosity
Generosity, or Generalization, refers to the concept of designing more general and abstract classes that can
serve as templates for more specific subclasses. Generalization enables inheritance, where a subclass inherits
properties and behavior from a superclass.
• Example: A class Animal could be generalized from specific classes like Dog and Cat.
7. Importance of Modelling
Modelling in software engineering refers to creating abstract representations of real-world systems to better
understand and design them. It helps visualize complex systems and communicate the design to stakeholders.
Modeling has rich history in all the engineering disciplines. That experience suggests four basic principles of
modeling.
8. Principles of Modelling
Four principles of modelling:
o The choice of what models to create has a profound influence on how a problem is attacked & how a
solution is shaped.
o Every model may be expressed at different levels of precision.
o The best models are connected to reality
o No single model is sufficient. Every non-trivial system is best approached through a small set of nearly
independent models.
9. Object-Oriented Modelling
In software, there are several ways to approach a model. The two most common ways are
1. Algorithmic perspective
2. Object-oriented perspective
Algorithmic Perspective
The traditional view of software development takes an algorithmic perspective. In this approach, the main
building block of all software is the procedure or function. This view leads developers to focus on issues of
control and the decomposition of larger algorithms into smaller ones. As requirements change and the system
grows, systems built with an algorithmic focus turn out to be very hard to maintain.
Object-Oriented Modelling (OOM) is the process of using object-oriented concepts to model a system. It uses
objects, classes, and their relationships to represent real-world entities and interactions within a system.
• Components of OOM:
o Objects: Represent real-world entities.
o Classes: Define the structure and behavior of objects.
o Inheritance: Allows new classes to reuse and extend existing classes.
o Associations: Define relationships between different objects.
UML (Unified Modeling Language) is a standardized visual language for creating object-oriented models of
software systems. It is used for specifying, visualizing, constructing, and documenting the artifacts of a system.
The Conceptual Model of UML provides a framework for understanding the key elements involved in object-
oriented software development.
• Key Elements:
o Things: Objects, classes, interfaces, components, and nodes.
o Relationships: Associations, dependencies, generalizations, and realizations.
o Diagrams: Visual representations like class diagrams, sequence diagrams, and use case
diagrams.
The UML Architecture is based on the 4+1 View Model of software architecture, which organizes a software
system’s architecture into five different views:
1. Design view: Encompasses the classes, interfaces, and collaborations that form the vocabulary of the
problem and its solution. This view primarily supports the functional requirements of the system,
meaning the services that the system should provide to its end users. With the UML, the static aspects of
this view are captured in class diagrams and object diagrams; the dynamic aspects of this view are
captured in interaction diagrams, state diagrams, and activity diagrams. The internal structure diagram
of a class is particularly useful.
2. Implementation view: Focuses on the organization of the software into modules and components
assemble and release the physical system. This view primarily addresses the configuration management
of the system’s releases, made up of somewhat independent files that can be assembled in various ways
to produce a running system. It is also concerned with the mapping from logical classes and components
to physical artifacts. With the UML, the static aspects of this view are captured in artifact diagrams; the
dynamic aspects of this view are captured in interaction diagrams, state diagrams, and activity
diagrams.
3. Interaction view: Depicts the dynamic aspects, Shows the flow of control among its various parts,
including possible concurrency and synchronization mechanisms. This view primarily addresses the
performance, scalability, and throughput of the system. With the UML, the static and dynamic aspects
of this view are captured in the same kinds of diagrams as for the design view, but with a focus on the
active classes that control the system and the messages that flow between them.
4. Deployment view: Encompasses the nodes that form the system's hardware topology on which the
system executes. This view primarily addresses the distribution, delivery, and installation of the parts
that make up the physical system. With the UML, the static aspects of this view are captured in
deployment diagrams; the dynamic aspects of this view are captured in interaction diagrams, state
diagrams, and activity diagrams.
5. Scenarios (Use Cases): Encompasses the use cases that describe the behavior of the system as seen by
its end users, analysts, and testers. This view doesn't really specify the organization of a software
system. Rather, it exists to specify the forces that shape the system's architecture. With the UML, the
static aspects of this view are captured in use case diagrams; the dynamic aspects of this view are
captured in interaction diagrams, state diagrams, and activity diagrams.
UNIT2
1. Classes
Classes are blueprints for creating objects. They define the properties (attributes) and behaviors (methods) that
an object created from the class will have.
• Terms:
o Attributes: Data fields (variables) of a class.
o Methods: Functions defined within a class that operate on the class's data.
o Visibility: Defines who can access certain attributes or methods (public, private, protected).
Example:
Person
Name: String
Age: int
Walk()
Talk()
2. Relationships
Relationships describe how classes and objects interact with each other.
• Types of Relationships:
1. Association: A general connection between classes, usually represented by a line.
2. Aggregation: A "whole-part" relationship, represented by a hollow diamond on the side of the
whole.
3. Composition: A stronger form of aggregation where the part cannot exist without the whole. It’s
represented by a filled diamond.
4. Inheritance (Generalization): Represents "is-a" relationships, shown by a line with a hollow
triangle pointing to the superclass.
5. Dependency: A weaker relationship indicating that one class uses another. It's represented by a
dashed line with an arrow.
In a multiplicity relationship, you can add a number directly to the associated line to indicate the number of
objects in the corresponding class.
• 1..1: Only one
• 0..*: Zero or more
• 1..*:one or more
• 0..1: No or only one
• m..n: at least m, at most n (m<=n)
Aggregation: The relationship between the whole and part, and the whole and part can be separated.
Composition relationship: The relationship between the whole and the part, but the whole and the part cannot
be separated.
Inheritance: used to describe the relationship between parent and child classes.
Dependencies: Assume that a change in class A causes a change in class B, then say that class B depends on
class A.
Realization: Realization is a relationship between the blueprint class and the object containing its respective
implementation level details.
Class Diagram Example: Order System
UML is made simpler by the presence of four common mechanisms that apply consistently throughout the
language.
1. Specifications
2. Adornments
3. Common divisions
4. Extensibility mechanisms
Specification: Every UML element has a specification behind it, which defines its properties, behaviors, and
relationships. These specifications serve as a foundation for visual models, allowing consistency between the
design and the actual system.
Adornments:
These are additional symbols or decorations that provide further information about an element in UML
diagrams. For example, an arrow on an association to show navigation, or visibility markers (+, -, #) on class
attributes and methods to specify access control.
Common Divisions:
UML uses divisions like class vs. instance and type vs. role to differentiate between general templates and
specific objects. For example:
• A class represents a blueprint, while an object is an instance of that class.
• Type vs. role differentiates between the abstract nature of an entity (type) and the specific part it plays
in a particular context (role).
Extensibility Mechanisms:
(i) Stereotypes: Extend the vocabulary of UML by defining new model elements based on existing ones.
Example: In a component diagram, a stereotype «database» can indicate that a component represents a
database system.
The include relationship represents mandatory functionality that is factored out of a base use case into a
separate use case. This separate use case must be included wherever the base use case is executed.
The extend relationship is used to show optional or conditional behavior. A base use case may or may
not be extended with additional behavior depending on certain conditions.
(ii) Tagged Values: Add additional information to an element (metadata). Example: A Customer class
could have a tagged value {status="active"}.
(iii) Constraints: Impose conditions on elements, shown in curly braces {}. Example: In a class diagram, a
constraint on an Account class could specify that the balance must always be non-negative. Class:
Account {balance >= 0}
4. Diagrams in UML
• Structural Diagrams: Include class diagrams, object diagrams, component diagrams, and deployment
diagrams.
• Behavioral Diagrams: Include use case diagrams, activity diagrams, sequence diagrams, and
collaboration diagrams.
Class & Object Diagrams
1. Class Diagrams
Class Diagrams represent the static structure of the system, showing classes and relationships between them.
Example:
• System Design:
o During the system design phase, class diagrams are used to model the static structure of a
software system. They help in visualizing and organizing classes, their attributes, methods, and
relationships, providing a blueprint for system implementation.
• Code Generation:
o Some software development environments and tools support code generation based on class
diagrams. Developers can generate code skeletons, reducing manual coding efforts and ensuring
consistency between the design and implementation.
o Testers use class diagrams to understand the relationships between classes and plan test cases
accordingly. The visual representation of class structures helps in identifying areas that require
thorough testing.
• Reverse Engineering:
o Class diagrams can be used for reverse engineering, where developers analyze existing code to
create visual representations of the software structure. This is especially helpful when
documentation is scarce or outdated.
2. Object Diagrams
Object Diagrams show instances of classes (objects) and their relationships at a particular point in time. They
provide a snapshot of the system.
Sequence Diagram: Depict the order of messages between objects over time. They emphasize the sequence
of messages rather than object relationships.
Messages
A message is a specific type of communication between two lifelines in an interaction. A message involves
following activities,
1. A call message which is used to call an operation.
2. A message to create an instance.
3. A message to destroy an instance.
4. For sending a signal.
When a lifeline receives a call message, it acts as a request to invoke an operation that has a similar
signature as specified in the message. When a lifeline is executing a message, it has a focus of control. As the
interaction progresses over time, the focus of control moves between various lifelines. This movement is
called a flow of control.
Following are the messages used in a System Interaction Diagram:
Message Name Meaning
Synchronous The sender of a message keeps waiting for the receiver to return control from the
message message execution.
Asynchronous The sender does not wait for a return from the receiver; instead, it continues the
message execution of a next message.
Return message The receiver of an earlier message returns the focus of control to the sender.
Object creation The sender creates an instance of a classifier.
Object destruction The sender destroys the created instance.
Found message The sender of the message is outside the scope of interaction.
Lost message The message never reaches the destination, and it is lost in the interaction.
• A sequence diagram shows an implementation of a scenario in the system. Lifelines in the system take
part during the execution of a system.
• In a sequence diagram, a lifeline is represented by a vertical bar.
• A message flow between two or more objects is represented using a vertical dotted line which extends
across the bottom of the page.
• In a sequence diagram, different types of messages and operators are used .
• In a sequence diagram, iteration and branching are also used.
Branching
In an interaction diagram, we can represent branching by adding guard conditions to the messages. Guard
conditions are used to check if a message can be sent forward or not. A message is sent forward only when its
guard condition is true. A message can have multiple guard conditions, or multiple messages can have the same
guard condition. Branching in UML is achieved with the help of alt and opt, operators.
The ordered sequence of events in a given sequence diagram is as follows:
1. Place an order.
2. Pay money to the cash counter.
3. Order Confirmation.
4. Order preparation.
5. Order serving.
If one changes the order of the operations, then it may result in crashing the program. It can also lead to
generating incorrect or buggy results.
Collaboration Diagrams:
Collaboration Diagrams are visual representations that depict interactions between objects to achieve a
particular goal in real time. They focus on object relationships and how objects send messages to one another.
These diagrams detail the roles, functionality, and behaviors of individual objects while also depicting the
overall operation of the system in a dynamic context.
• Depicting Messages:
o Messages are numbered to show the order of operations.
o Arrows represent the direction of the message flow.
• Polymorphism in Collaboration Diagrams:
o Collaboration diagrams can illustrate polymorphism by showing different objects responding to
the same message in different ways.
• Iterated Messages:
o Messages can be iterated or looped, often represented with an asterisk *.
• Use of Self in Messages:
o An object can send a message to itself to perform internal operations.
• Collaboration diagrams can become complex when too many objects are present within the system.
• It is hard to explore each object inside the system.
• Collaboration diagrams are time consuming.
• The object is destroyed after the termination of a program.
• The state of an object changes momentarily, which makes it difficult to keep track of every single
change the occurs within an object of a system.
A Use Case is a description of a system’s behavior from an external user’s perspective. It focuses on the
interaction between a user (actor) and the system.
Example1:
Example2:
Example3: Railway reservation use case diagram example:
2. Activity Diagrams
Activity Diagrams model workflows and the flow of control between activities. Activity Diagrams describe
how activities are coordinated to provide a service which can be at different levels of abstraction. To show
workflow of complex use cases activity diagrams are needed
Use Case and Activity Diagram for the Online Shopping System
1. The customer selects the “Browse Products” option from the main menu.
2. The system displays a list of all available products.
3. The customer can scroll through the list or use the search function to find specific products.
4. The customer can view product details, such as price, description, and images.
5. The customer can select a product to add it to their cart.
Library Management System
Use case diagram
Class diagram
Sequence Diagram
Collaboration diagram
Activity diagram