1 Object oriented design
1 Object oriented design
will do it.
What classes we need to implement a system that meets our
requirements?
What fields and methods will each class have?
Object-oriented manner
procedurally
Large program is divided into smaller programs called procedures,
also referred to as subprograms, subroutines, methods, or functions.
Each function solves part of the problem.
What happens when the size of the project increases?
Difficult to protect the data from inadvertent changes since most of the data
is generally global leading to the problem of spaghetti code.
Function is the most important component of the procedural design and the data
does not get
the due attention.
There are no access modifiers introduced in procedural programming.
Suffers from lack of inheritance, absence of code reusability. No way to
encapsulate data.
sequence of steps.
• This involves thinking about the functioning of your code as a step-by-step
• You just think about the different operations that need to happen in succession and
Spaghetti code/software
You are working for a vehicle parts manufacturer that needs to update
its online inventory system. Your boss asks you to program two similar
but separate forms for a website, one form that processes information
about cars and other does similar for trucks.
Attribute of cars required: Color, Engine size, Transmission type, Number of doors.
For trucks: Color, Engine size, Transmission type, Cab size, Towing capacity.
Suppose you suddenly also need to add a bus form, that records the
following information: Color, Engine Size, Transmission Type,
Number of passengers.
Procedural approach: An entire new forms needs to be created.
OOP:You can extend the vehicle class with a bus class and add the method
numberOfPassengers.
Object oriented software development
Before 1975, most software organizations used no specific techniques.
But with time these proved to be less successful and less acceptable because of:
The technique was unable to cope with the increasing size of software
products. It was suitable for software products up to 5000 lines of code.
The classical techniques could not scale up to handle large products
involving 5 million or more lines of codes.
The classical approach is either operation oriented or attribute (Data) oriented,
Compartment 1
Compartment 2
Object diagram with two instances.
Series of stages in project development
Development reaches a higher level only to fall back to a previous level and then again
climbing up till completion of the project. The process contains overlap and feedback.
The project goes through an evolutionary development lifecycle containing objects decided
at three different stages, namely:
b. Write the specifications of the requirements of the user and the software.
Examples: Examples:
Examples: Examples:
Landing, Loan,
Car, Mother,
Interrupt, Depositing
Telemetry Teacher,
Request, form, Search,
data, Politician,
Alert, Withdraw,
pressure Student,
Notification
sensors, Data
Financial Management System
Objects can be???
1. Investment,
2. Account
3. Transaction
4. Customer
Eg. A client object sends a message requesting a service from the server object.
The message activates a process or method on receiving the object.
This method will carry out the required processing and return the response.
UML, the Unified Modeling Language, is used to create diagrams describing the various aspects and uses
your our application before you begin coding, to ensure that you have everything covered.
Implementati
User’s view Structural view Behavioural view on
view
Defines the
Defines the kinds of
Captures how Captures the
functionalities objects interact
objects (classes) important
(facilities) made
important to the with each other to
available by the
components of the
understanding of the realize the system
system to its users. system and its
working of a system behaviour that
Internal structure, dependencies.
and its
dynamic behaviour of
captures the
implementation.
system components, dynamic behaviour
Captures relationship
the implementation is of the system.
among classes
not visible.
(objects).
A system has different stakeholders – people who have interests in different
aspects of the system.
E.g. Washing Machine,
If you are designing a washing machine’s motor, you have one view of the system.
If you are writing the operating instructions, you have another.
If you are designing the machine’s overall shape, you see the system different if you
just want
to wash the clothes.
Conscientious system design involves all the possible viewpoints, and each
UML diagram gives a way of incorporating a particular view.
The objective is to communicate clearly with every type of stakeholder.
Types of Design Modelling
They identify what classes there are, how they interrelate and how they interact.
Class Diagram helps construct the code for the software application development.
Classes
Basic class components
Attributes and Operations
Class Relationships
Associations
Generalizations
Aggregations and Compositions
Think over things in the world around you.
The things that surround you have attributes (properties) and they behave in certain ways.
These behaviours can be seen as a set of operations.
Passenger Student
Airplane Course
The association relationship indicates a relatively loose relationship between two classes.
This means the objects belonging to these associated classes can exist independently of each other.
However, if the relationship between two associated classes is tight, then it is represented by aggregation.
Aggregation, is thus a special form of association. One class contains another class.
Example: A Hospital has Departments.
Aggregation also represents composition – that is, one class made up of another class or classes.
The senior level aggregated class (Hospital) in the aggregation relationship has a diamond
on its right-hand side.
The “Whole” can exist without the “Part” and vice versa.
The relationship cannot be reciprocal. Hospital has Department, Department does not have Hospital.
Thus, it is a unidirectional association.
Students
College
Catalogue
Students can exist without college.
Teachers can exist without college.
Teachers
Products
Student Address
Building Flats
Car Engine
• The composition association relationship
connects the Person class with Brain class, Heart
class, and Legs class.
A company is associated
with 1 or more employees.
An employee is associated
with only 1 company.
We will discuss two types of directional associations:
Bi-directional
Uni-directional
BI-DIRECTIONAL (STANDARD) ASSOCIATION
Associations are always assumed to be bi-directional; this means that both classes are aware of each other
and their relationship.
UNI-DIRECTIONAL ASSOCIATION
In a uni-directional association, two classes are related, but only one class knows that the relationship
exists.
BI-DIRECTIONAL (STANDARD) ASSOCIATION
The multiplicity value next to the Plane class of 0..1 means that when an instance of a Flight exists, it can
either have one instance of a Plane associated with it or no Planes associated with it (i.e., maybe a plane has
not yet been assigned).
In this association, the Flight takes on the role of “assignedFlights”; the diagram tells us that the
Plane instance can be associated either with no flights (e.g., it’s a brand new plane) or with up
to an infinite number of flights (e.g., the plane has been in commission for the last five years).
UNI-DIRECTIONAL ASSOCIATION
NAVIGABILITY
Patient details Class Staff details Class Consultation Class Accounting Class
Diagram
Diagram Diagram Diagram
Patient Details Class Diagram
Staff Details Class Diagram
Consulting Class Diagram
Payment Class Diagram
Diagrams are an excellent structural representation of the system, allowing the modeler
to
capture all of the important entities in the problem space.
Class relationships demonstrate dependencies between classes that enable
understanding of the sequence in which messages are sent between their
corresponding objects.
Multiplicities provide valuable information on database modeling.
Class diagrams in design provide a modeling construct that is closest to coding.
Multiplicities in a class diagram aid in the creation of a relational database schema
by showing which tables require foreign keys to create the relation (i.e., classes with
many [*] relationships will require a foreign key when mapped to a table).
Class diagrams do not show any dynamic/behavioral information and thus do not display any concept of
time. They cannot show an “if-then-else” scenario, which makes them extremely weak in
representing the dynamics of a system.
The aggregation relationship, and variations of it (such as composition, not discussed in this
text), is unclear and has led to numerous debates and interpretations.
Attempting code generation from a class diagram without adequate preparation can lead to confusion
and errors.
Inappropriate level of usage. A developer should use the advanced class diagram, with extra
implementation classes and full signatures, at the solution level, whereas a business analyst should remain
at the business entity level and only show <> classes in these diagrams
Common Rectifying the errors Examples
Errors
Using Ensure a semantic relationship with “Car is a vehicle” has meaningful
inheritance commonalities for inheritance; commonalities—an inheritance relationship; but
instead of otherwise relate the two classes through a car and a driver will be an association
association. association. relationship
Paying too Start with an association relationship by Room and walls are more tightly associated,
much attention default. Move it to aggregation only if hence aggregation.
to association the relationship is so close that objects
vs. aggregation. from one class are tightly integrated
with objects from another class
Not adding As much as possible, add multiplicities When unsure, add “*” or “N” to indicate
multiplicities to association relationships. unknown multiplicities
in the
association
Common Rectifying the errors Examples
Errors
Adding Inheritance implies one class is a type Consider “car is a vehicle.” When this class
multiplicities of another class. The object instantiated design is instantiated, the single object that is
in inheritance from this inheritance relationship is a created has the definition of both a car and a
relationship. single object. vehicle. Therefore, there is no multiplicity
Therefore, multiplicities make no (number of objects of one class in relationship
sense here. with number of objects of another class) in a
car—vehicle inheritance relationship.