OOSD Unit-3
OOSD Unit-3
1. Objects:
○ Objects represent real-world entities or concepts. They have two main
components:
■ Attributes (data): The properties or state of an object.
■ Methods (behavior): The functions or operations that the object can
perform.
2. Classes:
○ A class is a blueprint for creating objects. It defines attributes and methods shared
by all instances (objects) of the class.
3. Encapsulation:
○ The design principle of encapsulation ensures that an object’s internal state is
hidden from the outside world. The data is protected using access modifiers (e.g.,
private, protected), exposing only necessary functionality through public methods.
4. Inheritance:
○ Inheritance allows for the creation of new classes based on existing ones. The new
class (subclass) inherits attributes and methods from the parent class (superclass),
which promotes code reuse and easier maintenance.
5. Polymorphism:
○ Polymorphism allows different classes to respond to the same method call in their
own way. This is achieved through method overriding and interfaces, enabling
more flexible and dynamic behavior.
6. Abstraction:
○ Abstraction focuses on defining essential features without getting into the details.
It simplifies complex systems by exposing only relevant details and hiding
unnecessary ones. In OOD, this is often done using abstract classes and interfaces.
1. Problem Analysis:
○ Understand the problem domain and identify key concepts. Break down the
problem into objects that interact with each other.
2. Design Classes and Objects:
○ Define the classes and their relationships (e.g., which objects interact, how they
are related). This includes determining attributes, methods, and access control
(encapsulation).
3. Define Relationships:
○ Identify the relationships between objects, such as:
■ Association: Objects interact with each other.
■ Aggregation: One object is part of another (whole-part relationship).
■ Composition: A stronger form of aggregation where one object cannot
exist without the other.
■ Inheritance: One object (subclass) inherits properties and behaviors from
another (superclass).
4. Use of UML (Unified Modeling Language):
○ OOD often uses UML diagrams to represent the system’s structure and behavior.
Key UML diagrams include:
■ Class Diagram: Shows the classes, their attributes, methods, and
relationships.
■ Sequence Diagram: Illustrates how objects interact in a specific sequence.
■ Use Case Diagram: Defines the system’s functionality from the user's
perspective.
5. Design Patterns:
○ Design patterns are reusable solutions to common problems in OOD. Examples
include:
■ Singleton Pattern: Ensures only one instance of a class.
■ Factory Pattern: Provides an interface for creating objects without
specifying their concrete class.
Intention of object oriented modeling and design is to learn how to apply object -oriented
concepts to all the stages of the software development life cycle.Object-oriented modeling and
design is a way of thinking about problems using models organized around real world concepts.
The fundamental construct is the object, which combines both data structure and behavior.
Purpose of Models:
Types of Models:
There are 3 types of models in the object oriented modeling and design are: Class Model, State
Model, and Interaction Model. These are explained as following below.
1. Class Model:
The class model shows all the classes present in the system. The class model shows
the attributes and the behavior associated with the objects.
The class diagram is used to show the class model.The class diagram shows the class
name followed by the attributes followed by the functions or the methods that are
associated with the object of the class.Goal in constructing class model is to capture
those concepts from the real world that are important to an application.
2. State Model:
State model describes those aspects of objects concerned with time and the
sequencing of operations – events that mark changes, states that define the context for
events, and the organization of events and states.Actions and events in a state diagram
become operations on objects in the class model. State diagram describes the state
model.
3. Interaction Model:
Interaction model is used to show the various interactions between objects, how the
objects collaborate to achieve the behavior of the system as a whole.
The following diagrams are used to show the interaction model:
● Use Case Diagram
● Sequence Diagram
● Activity Diagram
Designing Algorithm:
Let’s design an algorithm to calculate the total price of items in a shopping cart.
● Modularity: The algorithm is broken into smaller, reusable components (objects), making
it easier to modify, extend, or test.
● Maintainability: Changes to one part of the system (e.g., changing tax rate) are isolated in
the relevant class (Tax), reducing the impact on other parts of the system.
● Reusability: Methods like getTotalPrice() can be reused across different systems or
objects that need to calculate prices.
design optimization:
Design Optimization in OOSD refers to the process of improving the structure and performance
of a software system by making design decisions that enhance flexibility, maintainability,
scalability, and efficiency. In Object-Oriented Software Development (OOSD), optimization
focuses on making the design cleaner, more modular, and adaptable to change, while also
ensuring that the system performs efficiently.
By applying these principles, OOSD aims to produce efficient, maintainable, and scalable
software systems that can adapt to changing requirements and environments.
implementation of control
Implementation of Control in OOSD refers to the management of the flow of execution within a
software system using object-oriented principles. Control is crucial in determining how objects
interact, how methods are called, and how tasks are organized and executed in the system.
1. Method Invocation: Control flows through the invocation of methods on objects. Each
method represents an action that an object can perform, and control is transferred to these
methods when called.
○ Example: A Car object calls startEngine(), transferring control to the engine
startup process.
2. Object Interaction: Objects communicate by sending messages (method calls) to each
other, defining the flow of control across different parts of the system.
○ Example: A ShoppingCart interacts with Item objects to calculate the total price.
3. State Changes: The flow of control can depend on the state of an object. The behavior of
methods may vary based on the object's current state.
○ Example: A TrafficLight object changes its light color based on its state (RED,
GREEN, YELLOW).
4. Design Patterns: Patterns like the Command and Observer patterns control the flow of
execution by decoupling objects and allowing for more flexible handling of requests and
state changes.
○ Example: The Command Pattern allows requests to be encapsulated as objects
and executed at a later time, separating the request from the actual execution.
5. Event-Driven Programming: In systems like GUIs, control flows based on user actions
(like button clicks or key presses), which trigger event handlers to process these events.
○ Example: A button click triggers a onClick() method, controlling the subsequent
behavior.
6. Multi-threading: In concurrent systems, control is managed across multiple threads,
ensuring proper synchronization and coordination between tasks.
○ Example: A DownloadManager may use multiple threads to download files
concurrently.
adjustment of inheritance
Adjustment of Inheritance in Object-Oriented System Design (OOSD) refers to refining the use
of inheritance to ensure flexibility, maintainability, and scalability in a system. While inheritance
is a core principle of OOSD, improper or excessive use can lead to rigid and complex designs
that are difficult to modify or extend.
object representation
Object Representation in Object-Oriented System Design (OOSD) refers to how objects, which
are instances of classes, are modeled and organized within a software system. Each object
represents a real-world entity or concept, encapsulating both data (attributes) and behavior
(methods).
1. Encapsulation:
○ Encapsulation is the principle of bundling data and methods that operate on the
data into a single unit, the object. This hides the internal state of the object and
only exposes what is necessary through a defined interface (methods).
○ Example: A BankAccount object has private attributes like balance, and public
methods like deposit() and withdraw() to interact with the balance.
2. Attributes (Data Representation):
○ Objects represent entities with attributes (or properties) that hold data specific to
the object. These attributes can be simple (e.g., integers, strings) or complex (e.g.,
collections of other objects).
○ Example: A Person object might have attributes like name, age, and address.
3. Methods (Behavior Representation):
○ Objects also have methods that define their behavior, i.e., what actions the object
can perform or respond to. These methods manipulate the internal state and
interact with other objects.
○ Example: A Car object might have methods like startEngine(), stopEngine(), and
accelerate() to define its behavior.
4. Identity:
○ Every object has a unique identity, which distinguishes it from other objects. Even
if two objects have the same attribute values, they are still distinct entities in
memory.
○ Example: Two Car objects with the same make and model are still different
objects if they occupy different memory locations.
5. Inheritance:
○ Objects can inherit behavior and attributes from other classes, creating hierarchies
and allowing for shared functionality between similar objects. Subclasses extend
or modify the behavior of the parent class.
○ Example: A Dog class may inherit from a Mammal class, inheriting attributes like
legs and methods like breathe().
6. Polymorphism:
○ Objects of different classes can be treated as objects of a common superclass,
allowing methods to operate on objects of different types. This enables dynamic
method resolution at runtime.
○ Example: A Shape class can have subclasses like Circle and Rectangle. A method
that takes a Shape object can work with any subclass, allowing for flexible
handling of different shapes.
7. Abstraction:
○ Abstraction hides unnecessary complexity by exposing only relevant details to the
user. This allows objects to represent complex systems without overwhelming the
user with details.
○ Example: A Car object abstracts away the internal complexity of the engine,
transmission, and fuel system, presenting a simple interface like start() and stop().
physical packaging :
Physical Packaging in Object-Oriented System Design (OOSD) refers to the organization and
management of the physical deployment of objects, classes, and modules in the actual system
architecture. It involves structuring how the software components are stored, accessed, and
distributed in memory or across different devices, as well as ensuring efficient execution and
scalability.
Key Aspects of Physical Packaging in OOSD:
Physical packaging in OOSD focuses on how classes, objects, and modules are
organized, stored, and managed in memory or across systems. Proper packaging
ensures efficient resource use, scalability, maintainability, and the ability to
distribute and update the system effectively. Through modularization,
componentization, and careful memory and persistence management, physical
Structured Analysis and Structured Design (SA/SD) is a software development method that was
popular in the 1970s and 1980s. The method is based on the principle of structured
programming, which emphasizes the importance of breaking down a software system into
smaller, more manageable components.
In SA/SD, the software development process is divided into two phases: Structured Analysis and
Structured Design. During the Structured Analysis phase, the problem to be solved is analyzed
and the requirements are gathered. The Structured Design phase involves designing the system to
meet the requirements that were gathered in the Structured Analysis phase.
Some advantages of SA/SD include its emphasis on structured design and documentation, which
can help improve the clarity and maintainability of the system. However, SA/SD has some
disadvantages, including its rigidity and inflexibility, which can make it difficult to adapt to
changing business requirements or technological trends. Additionally, SA/SD may not be
well-suited for complex, dynamic systems, which may require more agile development
methodologies.
1. Requirements gathering: The first step in the SA/SD process is to gather requirements
from stakeholders, including users, customers, and business partners.
2. Structured Analysis: During the Structured Analysis phase, the requirements are
analyzed to identify the major components of the system, the relationships between
those components, and the data flows within the system.
3. Data Modeling: During this phase, a data model is created to represent the data used
in the system and the relationships between data elements.
4. Process Modeling: During this phase, the processes within the system are modeled
using flowcharts and data flow diagrams.
5. Input/Output Design: During this phase, the inputs and outputs of the system are
designed, including the user interface and reports.
6. Structured Design: During the Structured Design phase, the system is designed to
meet the requirements gathered in the Structured Analysis phase. This may include
selecting appropriate hardware and software platforms, designing databases, and
defining data structures.
7. Implementation and Testing: Once the design is complete, the system is implemented
and tested.
SA/SD has been largely replaced by more modern software development methodologies, but its
principles of structured analysis and design continue to influence current software development
practices. The method is known for its focus on breaking down complex systems into smaller
components, which makes it easier to understand and manage the system as a whole.
Basically, the approach of SA/SD is based on the Data Flow Diagram. It is easy to understand
SA/SD but it focuses on well-defined system boundary whereas the JSD approach is too complex
and does not have any graphical representation.
SA/SD is combined known as SAD and it mainly focuses on the following 3 points:
1. System
2. Process
3. Technology
1. Analysis Phase: It uses Data Flow Diagram, Data Dictionary, State Transition
diagram and ER diagram.
2. Design Phase: It uses Structure Chart and Pseudo Code.
1. Analysis Phase:
Analysis Phase involves data flow diagram, data dictionary, state transition diagram, and
entity-relationship diagram.
2. Data Dictionary:
The content that is not described in the DFD is described in the data dictionary. It
defines the data store and relevant meaning. A physical data dictionary for data
elements that flow between processes, between entities, and between processes and
entities may be included. This would also include descriptions of data elements that
flow external to the data stores.
A logical data dictionary may also be included for each such data element. All system
names, whether they are names of entities, types, relations, attributes, or services,
should be entered in the dictionary.
4. ER Diagram:
ER diagram specifies the relationship between data store. It is basically used in
database design. It basically describes the relationship between different entities.
2. Design Phase:
1. Structure Chart:
It is created by the data flow diagram. Structure Chart specifies how DFS’s processes
are grouped into tasks and allocated to the CPU. The structured chart does not show
the working and internal structure of the processes or modules and does not show the
relationship between data or data flows. Similar to other SASD tools, it is time and
cost-independent and there is no error-checking technique associated with this tool.
The modules of a structured chart are arranged arbitrarily and any process from a
DFD can be chosen as the central transform depending on the analysts’ own
perception. The structured chart is difficult to amend, verify, maintain, and check for
completeness and consistency.
2. Pseudo Code: It is the actual implementation of the system. It is an informal way of
programming that doesn’t require any specific programming language or technology.
1. Clarity and Simplicity: The SA/SD method emphasizes breaking down complex
systems into smaller, more manageable components, which makes the system easier
to understand and manage.
2. Better Communication: The SA/SD method provides a common language and
framework for communicating the design of a system, which can improve
communication between stakeholders and help ensure that the system meets their
needs and expectations.
3. Improved maintainability: The SA/SD method provides a clear, organized structure
for a system, which can make it easier to maintain and update the system over time.
4. Better Testability: The SA/SD method provides a clear definition of the inputs and
outputs of a system, which makes it easier to test the system and ensure that it meets
its requirements.
Jackson System Development (JSD) is a method of system development that covers the
software life cycle either directly or by providing a framework into which more specialized
techniques can fit. This article focuses on discussing JSD in detail.
Jackson system development is a linear system development approach that lets one describe and
model the real world. JSD can start from the stage in a project when there is only a general
statement of requirements.
1. However many projects that have used JSD started slightly later in the life cycle,
doing the first steps largely from existing documents rather than directly with the
users.
2. The later steps of JSD produce the code of the final system.
3. The output of the earlier steps is a set of program design problems.
1. Modelling Phase
In the modelling phase of JSD, the designer creates a collection of entity structure diagrams and
identifies the entities in the system, the actions they perform, the attributes of the actions and the
time order of the actions in the life of the entities.
2. Specification Phase
This phase focuses on actually what is to be done? Previous phase provides the basic for this
phase. An sufficient model of a time-ordered world must itself be time-ordered. Major goal is to
map progress in the real world on progress in the system that models it.
3. Implementation Phase
In the implementation phase JSD determines how to obtain the required functionality.
Implementation way of the system is based on the transformation of the specification into an
efficient set of processes. The processes involved in it should be designed in such a manner that
it would be possible to run them on available software and hardware.
Initially there were six steps when it was originally presented by Jackson, they were as below:
1. Entity/action step
2. Initial model step
3. Interactive function step
4. Information function step
5. System timing step
6. System implementation step
Later some steps were combined to create method with only three steps:
1. Modelling Step
In this step, the designer creates a collection of entity structure diagrams. The designer identifies
the entities in the system, actions they perform, the time-ordering of the actions in the life of the
entities, and the attributes of the actions and entities. Purpose is to create a good full description
of the aspects of the system and the organization and the developer has to decide which things
are important and which are not. Thus, aiding in good communication between developers and
the users of the new system.
2. Network Step
The network step involves modelling the system as a whole and representing as a System
Specification Diagram (SSD) also known as Network Diagram. It shows processes and how they
communicate with each other. Here, each entity becomes a process. The purpose of these
processes is to process the input, calculate output, and to keep the entity process up-to date.
3. Implementation Step
In the implementation stage, the abstract network model of the system is converted to the
physical system, represented as a system implementation diagram (SID). The SID shows the
scheduler process that calls modules that implement the processes. The goal here is the
optimization of the system. It is necessary here to reduce the number of processes as it is
impossible to provide each process contained in the specification its own virtual processor. The
processes are combined to limit the number of processors.
Benefits of JSD
Limitations of JSD
● Concept in OOP: Classes define blueprints for objects with attributes (data) and methods
(functions) encapsulated together.
● Mapping in Non-OOP Language: Use structures (e.g., struct in C) or records to simulate
classes. Attributes become fields within the structure, and methods can be implemented
as functions that accept the structure as a parameter.
2. Encapsulation
● Concept in OOP: Encapsulation involves bundling data and methods and restricting
direct access to some of the data (often through access modifiers like private or public).
● Mapping in Non-OOP Language: Encapsulation can be enforced through careful
structuring of functions. By convention, "private" fields can be managed by controlling
access functions and keeping data manipulation within a defined set of functions that act
as methods. This is often done by not exposing certain details in headers or by using
function pointers to limit access.
3. Inheritance
● Concept in OOP: Inheritance allows a new class to adopt properties and behavior from
an existing class.
● Mapping in Non-OOP Language: While inheritance isn’t directly supported, similar
behavior can be achieved through composition, where a structure includes another as a
field, simulating a "has-a" relationship instead of "is-a."
4. Polymorphism
5. Abstraction
● Concept in OOP: Abstraction hides complex implementation details and exposes only the
necessary parts of an object.
● Mapping in Non-OOP Language: Abstraction can be simulated by defining only essential
details in a structure and hiding implementation details in separate functions or modules.
Users of a data structure interact only with the exposed functions, unaware of underlying
complexities.
In object-oriented software development (OOSD), the process of translating a concept into data
structures involves: Understanding the problem, Choosing data structures, Building an object
model, and Refining the model.
Here are some additional tips for choosing data structures and algorithms for OOSD: Follow
design principles, Test and refactor, and Learn from examples.
OOSD is a method for developing software systems that focuses on the objects of a problem.
The goal of object-oriented design (OOD) is to create a description and specification that allows
developers to build, test, and reuse system components.
● Function Parameters: These variables, which indicate the data that the function
anticipates receiving when called, are specified in the parameter list of a function.
● Actual Parameters: The expressions or values passed in during a function call.
When the function is called, it receives these values as input.
● The parameters that the function signature declares. They serve as stand-ins for the
values that are provided in when the function is called.
1. Pass by Value
2. Pass by Reference
3. Pass by Pointers
1. Pass by Value
In Pass by Value method, a variable’s actual value is copied and then passed to the function
instead of the original variable. As the result, any changes to the parameter inside the function
will not affect the variable’s original value outside the function. Althogh it is easy to understand
and implement, this method is not so useful for large size of data structures at it involves copying
the value.
2. Pass by Reference
In pass-by-reference method, instead of passing the argument itself, we passes the reference of
an argument to the function. This allows the function to change the value of the original
argument.
Any changes we make to your argument inside your function are reflected in your original
argument so we have to be careful while handling data in this method.
3. Pass by Pointer
The pass-by-pointer is very similar to the pass-by-reference method. The only difference is that
we pass the raw pointers instead of reference to the function. It means that we pass the address of
the argument to the function.
implementing inheritance
The capability of a class to derive properties and characteristics from another class is called
Inheritance. Inheritance is one of the most important features of Object Oriented Programming in
C++. In this article, we will learn about inheritance in C++, its modes and types along with the
information about how it affects different properties of the class.
Syntax of Inheritance in C++
class derived_class_name : access-specifier base_class_name
// body ....
};
where,
association encapsulation:
data encapsulation in C++ is an important feature of OOP that provides data hiding,
access control, and a way to bundle data and methods together to create self-contained,
reusable, and maintainable code. It is a crucial concept that helps build robust and
modular software systems.
Encapsulation in C++ is defined as the wrapping up of data and information in a single unit. In
Object Oriented Programming, Encapsulation is defined as binding together the data and the
functions that manipulate them.
Consider a real-life example of encapsulation, in a company, there are different sections like the
accounts section, finance section, sales section, etc. Now,
● The finance section handles all the financial transactions and keeps records of all the
data related to finance.
● Similarly, the sales section handles all the sales-related activities and keeps records of
all the sales.
Two Important property of Encapsulation
1. Data Protection: Encapsulation protects the internal state of an object by keeping its
data members private. Access to and modification of these data members is restricted
to the class’s public methods, ensuring controlled and secure data manipulation.
2. Information Hiding: Encapsulation hides the internal implementation details of a
class from external code. Only the public interface of the class is accessible,
providing abstraction and simplifying the usage of the class while allowing the
internal implementation to be modified without impacting external code.
Features of Encapsulation
Below are the features of encapsulation:
1. We can not access any function from the class directly. We need an object to access
that function that is using the member variables of that class.
2. The function which we are making inside the class must use only member variables,
only then it is called encapsulation.
3. If we don’t make a function inside the class which is using the member variable of the
class then we don’t call it encapsulation.
4. Encapsulation improves readability, maintainability, and security by grouping data
and methods together.
5. It helps to control the modification of our data members.
Advantages & Disadvantages Of Encapsulation In C++
Encapsulation in C++ is a key idea in object-oriented programming (OOP concept) with several
advantages. Here are some of the primary advantages of data encapsulation in C++:
While there are multiple benefits of encapsulation, there can be scenarios where it might lead to
complications, especially when used excessively. Some such disadvantages of data encapsulation
in C++ are:
● Code Length: The code becomes longer and more verbose because you need to define
getter and setter methods for each data member. Thus, data encapsulation in C++ can also
make the code harder to read and maintain
● Potential for Errors: Overusing the concept of encapsulation in C++ programs can lead to
errors. Using setter methods introduces the potential for errors, as they may not always
validate or handle data correctly. For example, the setAge and setGPA methods in the
example do not handle invalid data gracefully.
● Limited Benefits: In some cases, the use of getter and setter methods (that are an integral
part of data encapsulation in C++) may provide limited benefits if the data members don't
require additional validation or logic during access or modification.
Encapsulation is a way of hiding an object's implementation details from its users. Data
encapsulation in C++ is implemented using private and public access specifiers, which control
the visibility of data and methods.
Abstraction, on the other hand, is a way of hiding the complexity of an object from its users. This
makes the object easier to understand and use, as the users do not need to know how the object
works internally. Abstraction in C++ is implemented using abstract classes and interfaces.
The table below provides a clear comparison between abstraction and data encapsulation in C++.
OOP
In C++, reusability in object-oriented programming (OOP) is the practice of reusing code in
multiple projects or parts of a program. This is achieved through OOP principles like
inheritance and composition, which support modularity and extensibility.
● Saves time and resources: Developers can use existing code instead of writing it from
scratch.
● Reduces redundancy: Developers don't have to write the same code multiple times.
● Improves maintainability: It's easier to modify code if it's reusable. For example, if
you need to fix a bug, you only have to modify it in one place.
● Ensures consistent software: Developers can create reliable software solutions more
efficiently.
Reusabilty means using the same code again and again without writing it twice. It is a concept
of OOP that is achieved via Inheritance. It helps to save memory and reduces the complexity of a
program. With the use of reusabilty we can add additional features to an existing class without
modifying it.
Extensibility means permitting language users to define new language features. Starting with a
base language and using various definition facilities an extensible language user can create new
notations, new data structures, new operations, and, sometimes, new regimes of control.
In object-oriented programming (OOP) in C++, robustness is the ability to write code that is
easy to use and hard to misuse. Robust code can handle unexpected actions and terminations
gracefully, displaying clear error messages to help users debug the program.
Here are some features of C++ that make it easier to write robust code: strict ownership of
resources, const correctness, value semantics, type safety, and deterministic destruction of
objects.
C++ is a good language choice for OOP because it provides strong support for OOP concepts.
These concepts include: encapsulation, inheritance, polymorphism, abstraction, and
composition.
By combining these concepts with good design practices and patterns, developers can create
robust, scalable, and maintainable applications.
Data Handling Data and functions are separate, Data and functions are bundled
with global or shared data within classes (encapsulation)
Modularity Functions serve as basic modules Classes and objects serve as modular
units
Data Hiding Data is exposed and accessible Data is protected within classes,
globally or passed between controlled access via public methods
functions
Example Usage Suitable for smaller, Ideal for large, complex systems
straightforward applications requiring modularity and reusability