SlideShare ist ein Scribd-Unternehmen logo
1 von 35
Clean code: SOLID
Maksym Husar
Mobile Team Lead, Indeema Software Inc.
Why do I need it?
The main reason why
Be relaxed. Keep calm.
One more reason why
First steps to Clean Code
DRY - «Don't repeat yourself»
KISS - «Keep it short and simple»
YAGNI - «You aren't gonna need it»
SOLID
SOLID principles
Why do I need SOLID?
It works fine without it...
SOLID as a life saver for the main problems of
a bad architecture:
● Fragility
A change may break unexpected parts — it is very difficult to detect if you
don’t have a good test coverage.
● Immobility
A component is difficult to reuse in another project—or in multiple places
of the same project—because it has too many coupled dependencies.
● Rigidity
A change requires a lot of efforts because it affects several parts of the
project.
Single responsibility principle
There should never be more than one reason for a class to change
Every time you create/change a class, you should ask yourself:
How many responsibilities does this class have?
==>
Single responsibility principle
Single responsibility principle
==>
Command-line script for showing the number of lines in a project:
find . -type f -exec wc -l {} + | sort -n
Basic check on clean code issues
Single responsibility principle
App Delegate is the most popular violator of the SRP principle.
Single responsibility principle
One of the possible ways to solve AppDelegate overloading is to use
Composite Design Pattern*:
* Highly recommend to
read: Refactoring
Massive App Delegate
Open/Closed principle
Entities (classes, modules, functions, etc.) should be open for extension, but
closed for modification.
● Open for extension: You should be able to extend or change the
behaviour of a class without efforts.
● Closed for modification: You must extend a class without changing the
implementation.
Open/Closed principle
Open/Closed principle
==>
*Decorator Design pattern is mainly focused on Open/Closed Principle.
Liskov substitution principle
Functions that use pointers on base classes must be able to use objects of
derived classes without knowing it.
To avoid violating this principle, the following restrictions must be applied:
● Preconditions cannot be strengthened in the subclass
● Postconditions cannot be weakened in the subclass
Liskov substitution principle. Bad inheritance example.
==>
Liskov substitution principle. Condition example.
Interface segregation principle
● "Many specialized interfaces are better than one universal"
or
● "Clients should not depend on methods that they do not use."
Interface segregation principle
Dependency inversion principle
High-level modules should not depend on low-level
modules. Both should depend on abstractions.
Abstractions should not depend on details. Details should
depend on abstractions.
Module - a logically interconnected set of functional elements.
Dependency inversion principle
Change in Е
Arrows show the direction of the relationship between the
modules.
Dependency inversion principle
Depend on abstractions,
not on details.
DataHandler
FilesystemStorage
Dependency inversion principle
Dependency inversion principle DataHandler
Storage
FilesystemStorage DropboxCloudStorage
Dependency inversion principle. Bad example.
Dependency inversion principle. Good example.
Obj-C & Swift Dependencies Visualizer
https://github.com/PaulTaykalo/
objc-dependency-visualizer
Most popular Dependency injection libraries
Swinject - https://github.com/Swinject/Swinject
Cleanse - https://github.com/square/Cleanse
Needle - https://github.com/uber/needle
Single responsibility - make modules smaller / simpler
Open/Closed - make modules extendable
Liskov substitution - inherit correctly
Interface segregation - split interfaces/protocols
Dependency inversion - use interfaces/protocols
Summary
https://www.scaledrone.com/blog/solid-principles-for-becoming-a-better-ios-
swift-developer/
https://marcosantadev.com/solid-principles-applied-swift/
https://medium.com/swift-india/solid-principles-part-1-single-responsibility-
ccfd4ff34a5a
https://www.vadimbulavin.com/refactoring-massive-app-delegate/
https://www.vadimbulavin.com/dependency-injection-in-swift/
Useful links

Weitere ähnliche Inhalte

Was ist angesagt?

Was ist angesagt? (20)

Introducing Clean Architecture
Introducing Clean ArchitectureIntroducing Clean Architecture
Introducing Clean Architecture
 
Clean Architecture Essentials - Stockholm Software Craftsmanship
Clean Architecture Essentials - Stockholm Software CraftsmanshipClean Architecture Essentials - Stockholm Software Craftsmanship
Clean Architecture Essentials - Stockholm Software Craftsmanship
 
SOLID Design Principles
SOLID Design PrinciplesSOLID Design Principles
SOLID Design Principles
 
Clean Architecture
Clean ArchitectureClean Architecture
Clean Architecture
 
Micro-frontend
Micro-frontendMicro-frontend
Micro-frontend
 
Hexagonal architecture with Spring Boot
Hexagonal architecture with Spring BootHexagonal architecture with Spring Boot
Hexagonal architecture with Spring Boot
 
Domain Driven Design
Domain Driven DesignDomain Driven Design
Domain Driven Design
 
Clean architecture
Clean architectureClean architecture
Clean architecture
 
Clean code: SOLID
Clean code: SOLIDClean code: SOLID
Clean code: SOLID
 
SOLID Principles and The Clean Architecture
SOLID Principles and The Clean ArchitectureSOLID Principles and The Clean Architecture
SOLID Principles and The Clean Architecture
 
Understanding react hooks
Understanding react hooksUnderstanding react hooks
Understanding react hooks
 
Domain-Driven Design
Domain-Driven DesignDomain-Driven Design
Domain-Driven Design
 
Real Life Clean Architecture
Real Life Clean ArchitectureReal Life Clean Architecture
Real Life Clean Architecture
 
2012 the clean architecture by Uncle bob
2012 the clean architecture by Uncle bob 2012 the clean architecture by Uncle bob
2012 the clean architecture by Uncle bob
 
SOLID Design Principles applied in Java
SOLID Design Principles applied in JavaSOLID Design Principles applied in Java
SOLID Design Principles applied in Java
 
SOLID Principles
SOLID PrinciplesSOLID Principles
SOLID Principles
 
Clean architecture with asp.net core
Clean architecture with asp.net coreClean architecture with asp.net core
Clean architecture with asp.net core
 
An Introduction to Redux
An Introduction to ReduxAn Introduction to Redux
An Introduction to Redux
 
Design principles - SOLID
Design principles - SOLIDDesign principles - SOLID
Design principles - SOLID
 
iOS architecture patterns
iOS architecture patternsiOS architecture patterns
iOS architecture patterns
 

Ähnlich wie Clean code: SOLID (iOS)

OO design principle
OO design principleOO design principle
OO design principle
Li-Wei Cheng
 

Ähnlich wie Clean code: SOLID (iOS) (20)

Soild principles
Soild principlesSoild principles
Soild principles
 
SOLID Principles
SOLID PrinciplesSOLID Principles
SOLID Principles
 
Solid principles
Solid principlesSolid principles
Solid principles
 
OO design principle
OO design principleOO design principle
OO design principle
 
Solid
SolidSolid
Solid
 
DesignPrinciples-and-DesignPatterns
DesignPrinciples-and-DesignPatternsDesignPrinciples-and-DesignPatterns
DesignPrinciples-and-DesignPatterns
 
android principle.pptx
android principle.pptxandroid principle.pptx
android principle.pptx
 
Becoming a better developer by using the SOLID design principles
Becoming a better developer by using the SOLID design principlesBecoming a better developer by using the SOLID design principles
Becoming a better developer by using the SOLID design principles
 
SOLID Software Principles with C#
SOLID Software Principles with C#SOLID Software Principles with C#
SOLID Software Principles with C#
 
S.O.L.I.D. principles of software development
S.O.L.I.D. principles of software developmentS.O.L.I.D. principles of software development
S.O.L.I.D. principles of software development
 
Solid Principles
Solid PrinciplesSolid Principles
Solid Principles
 
Entity Framework: To the Unit of Work Design Pattern and Beyond
Entity Framework: To the Unit of Work Design Pattern and BeyondEntity Framework: To the Unit of Work Design Pattern and Beyond
Entity Framework: To the Unit of Work Design Pattern and Beyond
 
Clean Code - Part 2
Clean Code - Part 2Clean Code - Part 2
Clean Code - Part 2
 
Software Design Principles (SOLID)
Software Design Principles (SOLID)Software Design Principles (SOLID)
Software Design Principles (SOLID)
 
GDSC - SOLID Principles session.pptx
GDSC - SOLID Principles session.pptxGDSC - SOLID Principles session.pptx
GDSC - SOLID Principles session.pptx
 
Birth of a developer
Birth of a developerBirth of a developer
Birth of a developer
 
Software design principles
Software design principlesSoftware design principles
Software design principles
 
An ultimate guide to SOLID Principles, developers must know.
An ultimate guide to SOLID Principles, developers must know.An ultimate guide to SOLID Principles, developers must know.
An ultimate guide to SOLID Principles, developers must know.
 
Object Oriented Design SOLID Principles
Object Oriented Design SOLID PrinciplesObject Oriented Design SOLID Principles
Object Oriented Design SOLID Principles
 
Design principles
Design principlesDesign principles
Design principles
 

Kürzlich hochgeladen

Obat Penggugur Kandungan Di Apotik Kimia Farma (087776558899)
Obat Penggugur Kandungan Di Apotik Kimia Farma (087776558899)Obat Penggugur Kandungan Di Apotik Kimia Farma (087776558899)
Obat Penggugur Kandungan Di Apotik Kimia Farma (087776558899)
Cara Menggugurkan Kandungan 087776558899
 

Kürzlich hochgeladen (6)

Mobile Application Development-Android and It’s Tools
Mobile Application Development-Android and It’s ToolsMobile Application Development-Android and It’s Tools
Mobile Application Development-Android and It’s Tools
 
Mobile Application Development-Components and Layouts
Mobile Application Development-Components and LayoutsMobile Application Development-Components and Layouts
Mobile Application Development-Components and Layouts
 
Satara Call girl escort *74796//13122* Call me punam call girls 24*7hour avai...
Satara Call girl escort *74796//13122* Call me punam call girls 24*7hour avai...Satara Call girl escort *74796//13122* Call me punam call girls 24*7hour avai...
Satara Call girl escort *74796//13122* Call me punam call girls 24*7hour avai...
 
Mobile App Penetration Testing Bsides312
Mobile App Penetration Testing Bsides312Mobile App Penetration Testing Bsides312
Mobile App Penetration Testing Bsides312
 
Obat Penggugur Kandungan Di Apotik Kimia Farma (087776558899)
Obat Penggugur Kandungan Di Apotik Kimia Farma (087776558899)Obat Penggugur Kandungan Di Apotik Kimia Farma (087776558899)
Obat Penggugur Kandungan Di Apotik Kimia Farma (087776558899)
 
Android Application Components with Implementation & Examples
Android Application Components with Implementation & ExamplesAndroid Application Components with Implementation & Examples
Android Application Components with Implementation & Examples
 

Clean code: SOLID (iOS)