0% found this document useful (0 votes)
16 views46 pages

Understanding S.O.L.I.D Design Principles

The document discusses the principles of good software design and architecture, emphasizing maintainability, understandability, and modularity. It introduces the S.O.L.I.D design principles, which aim to enhance software flexibility, maintainability, and cohesion, detailing each principle's objectives. Key principles include the Single Responsibility Principle, Open-Closed Principle, Liskov Substitution Principle, Interface Segregation Principle, and Dependency Inversion Principle.

Uploaded by

Kaman Khan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
16 views46 pages

Understanding S.O.L.I.D Design Principles

The document discusses the principles of good software design and architecture, emphasizing maintainability, understandability, and modularity. It introduces the S.O.L.I.D design principles, which aim to enhance software flexibility, maintainability, and cohesion, detailing each principle's objectives. Key principles include the Single Responsibility Principle, Open-Closed Principle, Liskov Substitution Principle, Interface Segregation Principle, and Dependency Inversion Principle.

Uploaded by

Kaman Khan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Software Design and

Architecture
Session 6
Design

A good design will manage all essential


complexities inherent in the problem without
adding to accidental complexities consequential
to the solutions.
The Object of Good Design

Maintainable:

Cost of system changes is minimal

Readily adaptable to modify existing functionality and enhance


functionality.
The Object of Good Design

Design is understandable.

Changes should be local in effect.

Design should be modular.


Goal is:

Low coupling and high cohesion.


S.O.L.I.D Design Principles-Introduction

Intended to make software design more:

Understandable
Flexible
Maintainable
S.O.L.I.D Design Principles History

Originally gathered by
Robert C. Martin
S.O.L.I.D Design Principles

S.O.L.I.D name given by

Michael Feathers
S.O.L.I.D Design Principles

S stands for

Principle Objective

Single Responsibility Principle (SRP) Increased Cohesion


S.O.L.I.D Design Principles

O stands for

Principle Objective

Flexibility,
Open-Closed Principle (OCP) Reusability, and
Maintainability
You can achieve it While using Inheritance and Polymorphism
S.O.L.I.D Design Principles

L stands for

Principle Objective

Liskov Substitution Principle (LSP) Proper Inheritance (IS A RULE)


S.O.L.I.D Design Principles

I stands for

Principle Objective

Deals with non-cohesive interfaces


Interface Segregation Principle (ISP)
for reducing coupling.
S.O.L.I.D Design Principles

D stands for

Principle Objective

Creation of reusable frameworks.


Dependency Inversion Principle (DIP)
Reduce inter-module coupling.
Single Responsibility Principle (SRP)

A class should have only one reason to


change.

It deals with cohesion.


Single Responsibility Principle (SRP)

A class should have only one reason to


change.

It deals with cohesion.


Cohesion

Defined as the functional relatedness of the


elements of a module.

Related to the force that cause a module, or a


class, to change.
Single Responsibility Principle (SRP)

A class should have only one reason to


change.

A class has only one responsibility.


What a class does:

The more a class does, the more likely it will


change.

The more a class changes, the more likely we


will introduce to bugs.
Single Responsibility Principle (SRP) Deals with Coupling & Cohesion

If a class has more than one responsibility:

Low Cohesion
High Coupling (The responsibilities become
coupled)
Single Responsibility Principle (SRP) Deals with Coupling & Cohesion

If a class has more than one responsibility:

Low Cohesion
High Coupling (The responsibilities become
coupled)
Single Responsibility Principle (SRP) Deals with Coupling & Cohesion

Changes to one responsibility may impair or


inhibit the class’s ability to meet the others.
Depends each other.
Single Responsibility Principle (SRP)

SRP one of the simplest of the principles but


one of the most difficult to get right.
Single Responsibility Principle (SRP)

Programmer Responsibility:

Finding and separating conjoined


responsibilities in much of what software
design in really about.
Single Responsibility Principle (SRP)

SRP is the fundamental principle.

Remaining four are depending some how.


Single Responsibility Principle (SRP) - Example

Create a new post

Log Error
Single Responsibility Principle (SRP) - Example
Single Responsibility Principle (SRP) - Example
The Open-Closed Principle (OCP)

A software artifact should be open for extension but closed


for modification.

The behavior of a software artifact ought to be extendible,


without having to modify that artifact.

Changing without change data, Like variable.


The Open-Closed Principle (OCP)

Not simply a principle that guides in the design of


classes and modules.

If simple extensions to the requirements force


massive changes to the software, then the architects
of that software system have engaged in a
spectacular failure.
The Open-Closed Principle (OCP)

Not simply a principle that guides in the design of


classes and modules.

If simple extensions to the requirements force


massive changes to the software, then the architects
of that software system have engaged in a
spectacular failure.
The Open-Closed Principle (OCP) – How to Apply

Inheritance

Composition

Association
The Open-Closed Principle (OCP) – Example
The Open-Closed Principle (OCP) – Example

What Happens if we had to add a case for

@
The Open-Closed Principle (OCP) – Example
The Open-Closed Principle (OCP) – Example

Make Separate class for Mention Post instead of changing in main.

Post

Tag Post Mention Post


Liskov’s Substitution Principle (LSP)

Subtypes must be substitutable for their base


types.

Deals with design of inheritance hierarchies.


Liskov’s Substitution Principle (LSP)

Functions that use references to base classes


must be able to use objects of derived classes
without knowing it.
Liskov’s Substitution Principle (LSP)

Behavior of derived class is not same as base


class generally.

Sub classes not behave like base.

Keypad mobile not hold touch behavior.


Liskov’s Substitution Principle (LSP) – Example
Liskov’s Substitution Principle (LSP) – Example
Liskov’s Substitution Principle (LSP) – Example

In this case;
By setting the width of a square object,
its height will change correspondingly
and vice versa. The square object will
remain a mathematically proper square.
Liskov’s Substitution Principle (LSP) – Example
SOLID Design Principles-Interface Segregation Principle
(ISP)

If you have an abstract class or


an interface, then the
implementers should not be
forced to implement parts that
they don’t care about.
SOLID Design Principles-Interface Segregation Principle
(ISP)

In programming, the interface


segregation principle states that
no client should be forced to
depend on methods it does not
use.
SOLID Design Principles-Interface Segregation Principle
(ISP)

Put more simple;

Do not add additional functionality


to an existing interface by adding
new methods.
SOLID Design Principles-Interface Segregation Principle
(ISP)

Instead, create a new


interface and let your class
implement multiple interfaces
if needed.

You might also like