SlideShare a Scribd company logo
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
OO Design Principles
PPTX
Learning solid principles using c#
PDF
Solid principles
PPTX
Is your code solid
PPTX
Design principle vs design patterns
PDF
Inversion of Control
PDF
TWINS: OOP and FP - Warburton
PDF
Software design principles - jinal desai
PPTX
Software Design Principles (SOLID)
PPTX
SOLID Principles in OOPS ooooooooo.pptx
PDF
Solid principle
PPT
principles of object oriented class design
PPT
DesignPrinciples-and-DesignPatterns
PPTX
CodeCamp Iasi 10 march 2012 - Scratching-SOLID
PDF
L22 Design Principles
PDF
Understanding SOLID Principles in OOP programming
PDF
Solid Principle
PDF
SOLID Design Principle
PPTX
L07 Design Principles
PPTX
Improving Software Quality Using Object Oriented Design Principles
OO Design Principles
Learning solid principles using c#
Solid principles
Is your code solid
Design principle vs design patterns
Inversion of Control
TWINS: OOP and FP - Warburton
Software design principles - jinal desai
Software Design Principles (SOLID)
SOLID Principles in OOPS ooooooooo.pptx
Solid principle
principles of object oriented class design
DesignPrinciples-and-DesignPatterns
CodeCamp Iasi 10 march 2012 - Scratching-SOLID
L22 Design Principles
Understanding SOLID Principles in OOP programming
Solid Principle
SOLID Design Principle
L07 Design Principles
Improving Software Quality Using Object Oriented Design Principles
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
Agentic AI : A Practical Guide. Undersating, Implementing and Scaling Autono...
PDF
Upgrade and Innovation Strategies for SAP ERP Customers
PPTX
CHAPTER 2 - PM Management and IT Context
PDF
Claude Code: Everyone is a 10x Developer - A Comprehensive AI-Powered CLI Tool
PDF
Design an Analysis of Algorithms I-SECS-1021-03
PDF
Internet Downloader Manager (IDM) Crack 6.42 Build 42 Updates Latest 2025
PDF
T3DD25 TYPO3 Content Blocks - Deep Dive by André Kraus
PPTX
Operating system designcfffgfgggggggvggggggggg
PDF
Odoo Companies in India – Driving Business Transformation.pdf
PPTX
Odoo POS Development Services by CandidRoot Solutions
PDF
SAP S4 Hana Brochure 3 (PTS SYSTEMS AND SOLUTIONS)
PDF
Which alternative to Crystal Reports is best for small or large businesses.pdf
PDF
PTS Company Brochure 2025 (1).pdf.......
PPTX
CHAPTER 12 - CYBER SECURITY AND FUTURE SKILLS (1) (1).pptx
PDF
Audit Checklist Design Aligning with ISO, IATF, and Industry Standards — Omne...
PDF
System and Network Administration Chapter 2
PDF
Why TechBuilder is the Future of Pickup and Delivery App Development (1).pdf
PDF
Navsoft: AI-Powered Business Solutions & Custom Software Development
PPTX
Lecture 3: Operating Systems Introduction to Computer Hardware Systems
PPTX
Online Work Permit System for Fast Permit Processing
Agentic AI : A Practical Guide. Undersating, Implementing and Scaling Autono...
Upgrade and Innovation Strategies for SAP ERP Customers
CHAPTER 2 - PM Management and IT Context
Claude Code: Everyone is a 10x Developer - A Comprehensive AI-Powered CLI Tool
Design an Analysis of Algorithms I-SECS-1021-03
Internet Downloader Manager (IDM) Crack 6.42 Build 42 Updates Latest 2025
T3DD25 TYPO3 Content Blocks - Deep Dive by André Kraus
Operating system designcfffgfgggggggvggggggggg
Odoo Companies in India – Driving Business Transformation.pdf
Odoo POS Development Services by CandidRoot Solutions
SAP S4 Hana Brochure 3 (PTS SYSTEMS AND SOLUTIONS)
Which alternative to Crystal Reports is best for small or large businesses.pdf
PTS Company Brochure 2025 (1).pdf.......
CHAPTER 12 - CYBER SECURITY AND FUTURE SKILLS (1) (1).pptx
Audit Checklist Design Aligning with ISO, IATF, and Industry Standards — Omne...
System and Network Administration Chapter 2
Why TechBuilder is the Future of Pickup and Delivery App Development (1).pdf
Navsoft: AI-Powered Business Solutions & Custom Software Development
Lecture 3: Operating Systems Introduction to Computer Hardware Systems
Online Work Permit System for Fast Permit Processing

Object Oriented Programming Ch3 SRP, DIP, ISP