Object Oriented Programming
in Swift
Ch 3
Single Responsibility Principle
Dependency Inversion Principle
Interface Segregation Principle
Sai Li @ Yowoo Tech.
2016/1/9
References
• Agile Software Development: Principles, Patterns,
and Practice ( : )

by Robert C. Martin
• Fundamental Object Oriented Programming 

by Hsuan-Tien Lin
• 

by Teddy Chen
• Essential Object-Oriented Programming

by Josh Ko
Cohesion & Coupling
Cohesion
• Degree to which the elements of a module belong
together
• The force that cause a module or a class to change
Coupling
• Degree of interdependence between software
modules
Cohesion & Coupling
Cohesion & Coupling
Goal: high cohesion, low coupling
S.O.L.I.D
• SRP: Single Responsibility Principle
• OCP: Open Closed Principle
• LSP: Liskov Substitution Principle
• ISP: Interface Segregation Principle
• DIP: Dependency Inversion Principle
Single Responsibility Principle
“A class should have one,
and only one, reason to change.”
SRP
SRP
Responsibility
• A reason for change
• More than one responsibility
• coupled responsibilities
• Fragile Design
Example
Needless Complexity? 

When?
Persistence
TDD
Single Responsibility Principle
• One of the simplest and hardest principle
• Software Design: The art of separating responsibility
S.O.L.I.D
• SRP: Single Responsibility Principle
• OCP: Open Closed Principle
• LSP: Liskov Substitution Principle
• ISP: Interface Segregation Principle
• DIP: Dependency Inversion Principle
Dependency Inversion Principle
1. High-level modules should not depend on low-
level modules. 

Both should depend on abstractions
2. Abstractions should not depend on details. Details
should depend on abstractions.
Inversion of Control
low level change -> high level change
Hollywood Principle: Don’t call me, I’ll call you
Inversion of Control
What they need
Switch
+ switch()
SwitchableDevicePolicy
Object Oriented Programming Ch3 SRP, DIP, ISP
– Robert C. Martin
“Depend on abstractions,
not on concretions.”
- Design Pattern , GoF
“Program to an interface,
not an implementation.”
S.O.L.I.D
• SRP: Single Responsibility Principle
• OCP: Open Closed Principle
• LSP: Liskov Substitution Principle
• ISP: Interface Segregation Principle
• DIP: Dependency Inversion Principle
Interface Pollution
Interface Pollution
Adaptor
Interface Segregation Principle
“Client should NOT be forced to depend
upon interfaces that they do not use”
Glass door
Separate Clients == Separate Interfaces
Object Oriented Programming Ch3 SRP, DIP, ISP
Object Oriented Programming Ch3 SRP, DIP, ISP
“Fat” Interface
• More than one responsibility
• Coupled responsibilities
• Fragile Design
• Clients depend on what they need only
Recap
• SRP: A class should have one, and only one, reason to change.
• DIP: Depend on abstractions, not on concretions.
• ISP: Make fine grained interfaces that are client specific
Recap Liskov Violation
Liskov Substitution Principle
Subtypes must be substitutable for their base
types.
Rectangle & Square Problem
Object Oriented Programming Ch3 SRP, DIP, ISP
Segment
Line
Ray
Line: isOn(point: Intercept) == true
LineSegment: isOn(point: Intercept) == ?
Object Oriented Programming Ch3 SRP, DIP, ISP
Object Oriented Programming Ch3 SRP, DIP, ISP
It’s the end
of the beginning
– Sai Li
“Live for interfaces, not implementations,
except Lovers”
References
• https://en.wikipedia.org/wiki/Cohesion_(computer_science)
• https://drive.google.com/file/d/0ByOwmqah_nuGNHEtcU5OekdDMkk/view?pli=1
• http://teddy-chen-tw.blogspot.tw/2011/12/1.html
• http://www.cs.utexas.edu/users/downing/papers/DIP.1996.pdf
• http://howard-lyrics.blogspot.tw/2011/04/test.html
• http://butunclebob.com/ArticleS.UncleBob.PrinciplesOfOod
• https://upload.wikimedia.org/wikipedia/commons/thumb/f/f8/Laptop-hard-drive-exposed.jpg/220px-Laptop-hard-drive-
exposed.jpg
• http://sce2.umkc.edu/BIT/burrise/pl/design/cohesion-coupling-abstract.gif
• http://freefeast.info/wp-content/uploads//2013/08/cohesion-vs.-coupling.jpg
• http://cdn.mos.cms.futurecdn.net/7047e9b7bfca2b3b6f352495885e77c2.jpg
• https://upload.wikimedia.org/wikipedia/commons/8/8d/DIPLayersPattern.png
• http://flylib.com/books/4/444/1/html/2/images/11_3.jpg
• http://flylib.com/books/4/444/1/html/2/images/11_4.jpg
• http://stg-tud.github.io/sedc/Lecture/ws13-14/Images/DIP-RegulatorBase.png
• http://stg-tud.github.io/sedc/Lecture/ws13-14/Images/DIP-RegulatorDIPCompliant.png
• http://www.coolmath.com/sites/cmat/files/images/03-lines-01.gif
• http://flylib.com/books/4/444/1/html/2/images/12_2.jpg
• http://flylib.com/books/4/444/1/html/2/images/12_1.jpg

More Related Content

PPTX
SOLID Principles
PPTX
SOLID Principles
PPTX
Managing state in modern React web applications
PDF
Beyond Fault Tolerance with Actor Programming
PDF
Object Oriented Programming in Swift Ch1 - Inheritance
PDF
Shamaeva fearless sourcing on LinkedIn 19.2.2014
PPTX
Advanced Search Techniques for Sourcing Ninjas | Talent Connect Vegas 2013
PDF
Lou Adler & LinkedIn Master Class: Sourcing Strategies & Out-of-the-box Boole...
SOLID Principles
SOLID Principles
Managing state in modern React web applications
Beyond Fault Tolerance with Actor Programming
Object Oriented Programming in Swift Ch1 - Inheritance
Shamaeva fearless sourcing on LinkedIn 19.2.2014
Advanced Search Techniques for Sourcing Ninjas | Talent Connect Vegas 2013
Lou Adler & LinkedIn Master Class: Sourcing Strategies & Out-of-the-box Boole...

Similar to Object Oriented Programming Ch3 SRP, DIP, ISP (20)

PPTX
SOLID_Principles_Explained_Presentation.pptx
PPTX
Software Design Principles (SOLID)
PPTX
Birth of a developer
PPT
SOLID principles-Present
PPTX
Apply SOLID Design principles to javascript code with immediate function invo...
PDF
Solid principles
PPTX
Solid principles
PPTX
Solid Principles
PPT
Software Design Principles
PPTX
SOLID Principles in OOPS ooooooooo.pptx
PPTX
OO Design Principles
PPTX
PPTX
Solid as OOP abstraction
PPTX
Design Pattern lecture 1
PDF
Solid principle
PPT
SOLID in PHP
PPTX
Solid-Principles
PPT
Design poo my_jug_en_ppt
PPTX
Single Responsibility Principle
PPTX
Shooting at a Moving Target
SOLID_Principles_Explained_Presentation.pptx
Software Design Principles (SOLID)
Birth of a developer
SOLID principles-Present
Apply SOLID Design principles to javascript code with immediate function invo...
Solid principles
Solid principles
Solid Principles
Software Design Principles
SOLID Principles in OOPS ooooooooo.pptx
OO Design Principles
Solid as OOP abstraction
Design Pattern lecture 1
Solid principle
SOLID in PHP
Solid-Principles
Design poo my_jug_en_ppt
Single Responsibility Principle
Shooting at a Moving Target
Ad

More from Chihyang Li (20)

PDF
Image Style Transfer and AI on iOS Mobile App
PDF
Image style transfer and iOS CoreML, Vision Frameworks
PDF
Machine Learning in Swift
PDF
Image style transfer & AI on App
PDF
iOS Vision framework
PDF
Design Patterns in Swift Ch5 Abstract Factory Builder
PDF
Design patterns in Swift Ch4: Iterator & Template Method
PDF
Swift map & flatMap
PDF
Swift Optional ??
PDF
Design Pattern in Swift Ch2 Strategy, Decorator
PDF
Design Pattern Ch3 in Swift Composite
PDF
Design Patterns in Swift Ch1 Factory Method
PDF
Scrum & Kanban Introduction
PDF
Design Patterns in Swift ch0 Introduction
PDF
Object Oriented Programming in Swift Ch2 Polymorphism, OCP, LSP
PDF
Object Oriented Programming in Swift Ch0 - Encapsulation
PDF
Apple Swift API Design Guideline
PDF
Swift capture
PDF
DevOps 2016 summit
PDF
Slack introduction
Image Style Transfer and AI on iOS Mobile App
Image style transfer and iOS CoreML, Vision Frameworks
Machine Learning in Swift
Image style transfer & AI on App
iOS Vision framework
Design Patterns in Swift Ch5 Abstract Factory Builder
Design patterns in Swift Ch4: Iterator & Template Method
Swift map & flatMap
Swift Optional ??
Design Pattern in Swift Ch2 Strategy, Decorator
Design Pattern Ch3 in Swift Composite
Design Patterns in Swift Ch1 Factory Method
Scrum & Kanban Introduction
Design Patterns in Swift ch0 Introduction
Object Oriented Programming in Swift Ch2 Polymorphism, OCP, LSP
Object Oriented Programming in Swift Ch0 - Encapsulation
Apple Swift API Design Guideline
Swift capture
DevOps 2016 summit
Slack introduction
Ad

Recently uploaded (20)

PPTX
Cybersecurity-and-Fraud-Protecting-Your-Digital-Life.pptx
PDF
Topaz Photo AI Crack New Download (Latest 2025)
PDF
Practical Indispensable Project Management Tips for Delivering Successful Exp...
PDF
Microsoft Office 365 Crack Download Free
PPTX
Lecture 5 Software Requirement Engineering
PDF
Type Class Derivation in Scala 3 - Jose Luis Pintado Barbero
PDF
Guide to Food Delivery App Development.pdf
PDF
Workplace Software and Skills - OpenStax
PDF
Visual explanation of Dijkstra's Algorithm using Python
PDF
MCP Security Tutorial - Beginner to Advanced
DOCX
How to Use SharePoint as an ISO-Compliant Document Management System
PDF
The Dynamic Duo Transforming Financial Accounting Systems Through Modern Expe...
PDF
Introduction to Ragic - #1 No Code Tool For Digitalizing Your Business Proces...
PPTX
Tech Workshop Escape Room Tech Workshop
PDF
BoxLang Dynamic AWS Lambda - Japan Edition
PPTX
CNN LeNet5 Architecture: Neural Networks
PPTX
Full-Stack Developer Courses That Actually Land You Jobs
PDF
Internet Download Manager IDM Crack powerful download accelerator New Version...
PDF
Multiverse AI Review 2025: Access All TOP AI Model-Versions!
PDF
EaseUS PDF Editor Pro 6.2.0.2 Crack with License Key 2025
Cybersecurity-and-Fraud-Protecting-Your-Digital-Life.pptx
Topaz Photo AI Crack New Download (Latest 2025)
Practical Indispensable Project Management Tips for Delivering Successful Exp...
Microsoft Office 365 Crack Download Free
Lecture 5 Software Requirement Engineering
Type Class Derivation in Scala 3 - Jose Luis Pintado Barbero
Guide to Food Delivery App Development.pdf
Workplace Software and Skills - OpenStax
Visual explanation of Dijkstra's Algorithm using Python
MCP Security Tutorial - Beginner to Advanced
How to Use SharePoint as an ISO-Compliant Document Management System
The Dynamic Duo Transforming Financial Accounting Systems Through Modern Expe...
Introduction to Ragic - #1 No Code Tool For Digitalizing Your Business Proces...
Tech Workshop Escape Room Tech Workshop
BoxLang Dynamic AWS Lambda - Japan Edition
CNN LeNet5 Architecture: Neural Networks
Full-Stack Developer Courses That Actually Land You Jobs
Internet Download Manager IDM Crack powerful download accelerator New Version...
Multiverse AI Review 2025: Access All TOP AI Model-Versions!
EaseUS PDF Editor Pro 6.2.0.2 Crack with License Key 2025

Object Oriented Programming Ch3 SRP, DIP, ISP