Lecture 13 - OO Design
Lecture 13 - OO Design
LECTURE 13
OBJECT ORIENTED DESIGN
Design Problems
Mainly there are three kinds of problems
Rigidity
Immobility
Fragility
1
6/2/2022
Rigidity
Immobility
2
6/2/2022
Fragility
Design Principles
To overcome these problems, we have some
guidelines that we can follow called design
principles
These are the principles upon which object
oriented programming is built on
Mainly you can apply these five principles to
have a good design
SOLID principles
3
6/2/2022
4
6/2/2022
5
6/2/2022
6
6/2/2022
7
6/2/2022
8
6/2/2022
Example of ISP
Burger Place (Without ISP)
9
6/2/2022
Example of ISP
10
6/2/2022
Fragility
Immobility
11
6/2/2022
Design Patterns
A design pattern is a general solution for a
common software design problem
These are tested and proven to be more
effective when included in the design
There are three kinds
Creational
Structural
Behavioral
12
6/2/2022
Singleton
What it is?
Ensures that a class that is responsible for creating an
object is allowed to create only one instance, and
provide a global point of access to it.
Creational
Example
The office of the President of the United States is a
Singleton. The United States Constitution specifies the
means by which a president is elected, limits the term of
office, and defines the order of succession. As a result,
there can be at most one active president at any given
time. Regardless of the personal identity of the active
president, the title, "The President of the United States" is
a global point of access that identifies the person in the
office.
13
6/2/2022
Structural
Façade
What it is?
❖ Defines a unified, higher level interface to a
subsystem that makes it easier to use.
Example
Consumers encounter a Facade when ordering from a
catalog. The consumer calls one number and speaks
with a customer service representative. The customer
service representative acts as a Facade, providing an
interface to the order fulfillment department, the billing
department, and the shipping department.
Behavioral
Strategy
What it is?
❖ Define a family of algorithms, encapsulate each one, and
make them interchangeable.
❖ Strategy lets the algorithm vary independently from the
clients that use it.
❖ Capture the abstraction in an interface, bury
implementation details in derived classes.
14
6/2/2022
Behavioral
Example
Several options exist such as driving one's own car, taking a
taxi, an airport shuttle, a city bus, or a limousine service. For
some airports, subways and helicopters are also available as
a mode of transportation to the airport. Any of these modes
of transportation will get a traveler to the airport, and they
can be used interchangeably. The traveler must chose the
Strategy based on tradeoffs between cost, convenience, and
time.
15