SlideShare a Scribd company logo
Datascope Systems Ltd.
How to write meaningful code
Bullet Points
 SOLID
• Single Responsibility Principle
• Open/Closed Principle
• Liskov Substitution Principle
• Inversion Of control
• Dependency Inversion Principle
 POLA
 Demeter Law
 Lowering Principle
 Live project example
Single Responsibility
principle
 The class has only one reason to change!
 Repository – is that a good example? What if
persistence mechanism for saving/retrieving business entities will be
changed separately? CQRS!
 Facade pattern for interacting with printing
subsystem.
RFID Facade example
Class has more than 1 responsibility, but only one reason to change.
Open-Closed
principle
Open-Closed
principle
 Modules should be open for extension but
closed to modification
Barbara-Liskov substitution
principle
x(O) = y(O) if Y is type of T,
and T is derived from X a subtype of X
Interface Segregation
Principle
Interface Segregation
Principle
Let’s imagine we have an interface which is pretty
much the same as a sub-repository
This is how saving/loading supposed to look like
And Boooooom, at some point business requires only
read-only settings
Interface Segregation
Principle
Load probably will be similarly to that then …
And start from here we have breach ISP.
Client should not depend on any method he is not using
Interface Segregation
Principle
Solution: split into two interfaces
Interface Segregation
Principle
Dependency Inversion
Principle
Dependency Inversion
Principle
 Example of inversion of control in DB is a
many to many relation. Order has no idea of
OrderDetails existence. As long as you have
a magic word
 1) using i.e C#
 2) import i.e. Java
 3) include i.e C,C++
You have an arrow pointing from you (you are
depend on smth…)
Examples
Time to go Real…
Let’s be interactive
DeliveryCollectionHelper vs
POLA and SRP
ФабричноЛоггеровыйКартинкоДоставочноСервисныйХелпер
Factory OR DI?
ЗависимостиИнжектируемаяСинглтоноФабрика
Let’s apply some refactoring
Get rid of unnecessary dependencies
and apply SRP. Lowering Law, Internal Coupling,
Descriptors and Views (Logical diff), Refactoring stages
OCP
Unnecessary coupling
(Class contains two
services), horizontal
dependencies, try to avoid
that
Strategy and Factory
Strategy and Factory
Strategy is ready, but still something
is wrong??? Proper Factory
Usage of Factory and Strategies example
Test is pretty damn simple
What`s wrong here?
Class usage example:
Class definition (object will goes down to service layer):
Demeter law in action
• Each unit should have only limited knowledge about other units:
only units "closely" related to the current unit.
• Each unit should only talk to its friends; don't talk to strangers.
• Only talk to your immediate friends.
Demeter law in action
What about up/down casting through
explicit operator? Hide SP’s - Sort of ACL
Right way of doing it
(this is service layer)
Testability problem.
Action chain solution
Action chain usage
ISP in action
ISP in action
DI in action
DI in action (diff between DIP and
Dependency Injection)
DI in action (more complicated example)
What if you need sort of magnet objects like reports,
user roles, email generators etc.
So, how to invert arrows ?
How to get rid of using, import etc in target class
DI in action (report example)
Dependency diagram you want to achieve:
DI in action (report example)
Reports side effect
(two reports 99% equals)
This is how it looks like in practice:
Report application layer
Report Collector in action
My LSP mistake in Quilt project
Software Development is amazing!

More Related Content

Similar to SOLID and Clean Code with life project example

Object Oriented Concepts and Principles
Object Oriented Concepts and PrinciplesObject Oriented Concepts and Principles
Object Oriented Concepts and Principles
deonpmeyer
 
Design poo my_jug_en_ppt
Design poo my_jug_en_pptDesign poo my_jug_en_ppt
Design poo my_jug_en_ppt
agnes_crepet
 
What To Leave Implicit
What To Leave ImplicitWhat To Leave Implicit
What To Leave Implicit
Martin Odersky
 
Improving Software Quality Using Object Oriented Design Principles
Improving Software Quality Using Object Oriented Design PrinciplesImproving Software Quality Using Object Oriented Design Principles
Improving Software Quality Using Object Oriented Design Principles
Dr. Syed Hassan Amin
 
Software design principles - jinal desai
Software design principles - jinal desaiSoftware design principles - jinal desai
Software design principles - jinal desai
jinaldesailive
 
Common Design Patterns.pptx
Common Design Patterns.pptxCommon Design Patterns.pptx
Common Design Patterns.pptx
fake195786
 
Refactoring to SOLID Code
Refactoring to SOLID CodeRefactoring to SOLID Code
Refactoring to SOLID Code
Adil Mughal
 
How to organize the business layer in software
How to organize the business layer in softwareHow to organize the business layer in software
How to organize the business layer in software
Arnaud LEMAIRE
 
Jump Start To Ooad And Design Patterns
Jump Start To Ooad And Design PatternsJump Start To Ooad And Design Patterns
Jump Start To Ooad And Design Patterns
Lalit Kale
 
Jump start to OOP, OOAD, and Design Pattern
Jump start to OOP, OOAD, and Design PatternJump start to OOP, OOAD, and Design Pattern
Jump start to OOP, OOAD, and Design Pattern
Nishith Shukla
 
Segue to design patterns
Segue to design patternsSegue to design patterns
Segue to design patterns
Rahul Singh
 
OO Design Principles
OO Design PrinciplesOO Design Principles
OO Design Principles
Anju Kanjirathingal
 
AEM Clean Code - Miklos Csere
AEM Clean Code - Miklos Csere AEM Clean Code - Miklos Csere
AEM Clean Code - Miklos Csere Miklos Csere
 
SOLID principles-Present
SOLID principles-PresentSOLID principles-Present
SOLID principles-PresentQuang Nguyen
 
Design principle vs design patterns
Design principle vs design patternsDesign principle vs design patterns
Design principle vs design patterns
Prabhakar Sharma
 
EuroAD 2021: ChainRules.jl
EuroAD 2021: ChainRules.jl EuroAD 2021: ChainRules.jl
EuroAD 2021: ChainRules.jl
Lyndon White
 
What To Leave Implicit
What To Leave ImplicitWhat To Leave Implicit
What To Leave Implicit
Martin Odersky
 

Similar to SOLID and Clean Code with life project example (20)

Spring fundamentals
Spring fundamentalsSpring fundamentals
Spring fundamentals
 
Object Oriented Concepts and Principles
Object Oriented Concepts and PrinciplesObject Oriented Concepts and Principles
Object Oriented Concepts and Principles
 
Design poo my_jug_en_ppt
Design poo my_jug_en_pptDesign poo my_jug_en_ppt
Design poo my_jug_en_ppt
 
What To Leave Implicit
What To Leave ImplicitWhat To Leave Implicit
What To Leave Implicit
 
Improving Software Quality Using Object Oriented Design Principles
Improving Software Quality Using Object Oriented Design PrinciplesImproving Software Quality Using Object Oriented Design Principles
Improving Software Quality Using Object Oriented Design Principles
 
Software design principles - jinal desai
Software design principles - jinal desaiSoftware design principles - jinal desai
Software design principles - jinal desai
 
Common Design Patterns.pptx
Common Design Patterns.pptxCommon Design Patterns.pptx
Common Design Patterns.pptx
 
Refactoring to SOLID Code
Refactoring to SOLID CodeRefactoring to SOLID Code
Refactoring to SOLID Code
 
How to organize the business layer in software
How to organize the business layer in softwareHow to organize the business layer in software
How to organize the business layer in software
 
Jump Start To Ooad And Design Patterns
Jump Start To Ooad And Design PatternsJump Start To Ooad And Design Patterns
Jump Start To Ooad And Design Patterns
 
Jump start to OOP, OOAD, and Design Pattern
Jump start to OOP, OOAD, and Design PatternJump start to OOP, OOAD, and Design Pattern
Jump start to OOP, OOAD, and Design Pattern
 
Segue to design patterns
Segue to design patternsSegue to design patterns
Segue to design patterns
 
OO Design Principles
OO Design PrinciplesOO Design Principles
OO Design Principles
 
AEM Clean Code - Miklos Csere
AEM Clean Code - Miklos Csere AEM Clean Code - Miklos Csere
AEM Clean Code - Miklos Csere
 
Python SOLID
Python SOLIDPython SOLID
Python SOLID
 
SOLID principles-Present
SOLID principles-PresentSOLID principles-Present
SOLID principles-Present
 
SOLID Principles
SOLID PrinciplesSOLID Principles
SOLID Principles
 
Design principle vs design patterns
Design principle vs design patternsDesign principle vs design patterns
Design principle vs design patterns
 
EuroAD 2021: ChainRules.jl
EuroAD 2021: ChainRules.jl EuroAD 2021: ChainRules.jl
EuroAD 2021: ChainRules.jl
 
What To Leave Implicit
What To Leave ImplicitWhat To Leave Implicit
What To Leave Implicit
 

More from vasya_bh

Лікнеп по PR-комунікаціямм (Дарина Примак)
Лікнеп по PR-комунікаціямм (Дарина Примак)Лікнеп по PR-комунікаціямм (Дарина Примак)
Лікнеп по PR-комунікаціямм (Дарина Примак)
vasya_bh
 
Smart grid as a future grid of a power distributed systems!
Smart grid as a future grid of a power distributed systems!Smart grid as a future grid of a power distributed systems!
Smart grid as a future grid of a power distributed systems!
vasya_bh
 
Молодіжний делегат України до ООН
Молодіжний делегат України до ООНМолодіжний делегат України до ООН
Молодіжний делегат України до ООН
vasya_bh
 
Битва за контент: брендований vs небрендований
Битва за контент: брендований vs небрендованийБитва за контент: брендований vs небрендований
Битва за контент: брендований vs небрендований
vasya_bh
 
I gov chernihiv-ihub
I gov chernihiv-ihubI gov chernihiv-ihub
I gov chernihiv-ihub
vasya_bh
 
I gov. организация-фронтед-части.
I gov. организация-фронтед-части.I gov. организация-фронтед-части.
I gov. организация-фронтед-части.
vasya_bh
 
Сонячна енергетика лекція I hub 2015
Сонячна енергетика лекція I hub 2015Сонячна енергетика лекція I hub 2015
Сонячна енергетика лекція I hub 2015
vasya_bh
 
Behance Portfolio Review презентація Дмитра Скварського в IHUB Chernihiv
Behance Portfolio Review презентація Дмитра Скварського в IHUB ChernihivBehance Portfolio Review презентація Дмитра Скварського в IHUB Chernihiv
Behance Portfolio Review презентація Дмитра Скварського в IHUB Chernihiv
vasya_bh
 
"постійний потік клієнтів на автоматі" презентація в IHUB
"постійний потік клієнтів на автоматі" презентація в IHUB "постійний потік клієнтів на автоматі" презентація в IHUB
"постійний потік клієнтів на автоматі" презентація в IHUB
vasya_bh
 
"8 words a day" презентація в IHUB Chernihiv
"8 words a day" презентація в IHUB Chernihiv"8 words a day" презентація в IHUB Chernihiv
"8 words a day" презентація в IHUB Chernihiv
vasya_bh
 
Як досягти своїх цілей. Логіка сучасних способів взаємодії.
Як досягти своїх цілей. Логіка сучасних способів взаємодії.Як досягти своїх цілей. Логіка сучасних способів взаємодії.
Як досягти своїх цілей. Логіка сучасних способів взаємодії.
vasya_bh
 

More from vasya_bh (11)

Лікнеп по PR-комунікаціямм (Дарина Примак)
Лікнеп по PR-комунікаціямм (Дарина Примак)Лікнеп по PR-комунікаціямм (Дарина Примак)
Лікнеп по PR-комунікаціямм (Дарина Примак)
 
Smart grid as a future grid of a power distributed systems!
Smart grid as a future grid of a power distributed systems!Smart grid as a future grid of a power distributed systems!
Smart grid as a future grid of a power distributed systems!
 
Молодіжний делегат України до ООН
Молодіжний делегат України до ООНМолодіжний делегат України до ООН
Молодіжний делегат України до ООН
 
Битва за контент: брендований vs небрендований
Битва за контент: брендований vs небрендованийБитва за контент: брендований vs небрендований
Битва за контент: брендований vs небрендований
 
I gov chernihiv-ihub
I gov chernihiv-ihubI gov chernihiv-ihub
I gov chernihiv-ihub
 
I gov. организация-фронтед-части.
I gov. организация-фронтед-части.I gov. организация-фронтед-части.
I gov. организация-фронтед-части.
 
Сонячна енергетика лекція I hub 2015
Сонячна енергетика лекція I hub 2015Сонячна енергетика лекція I hub 2015
Сонячна енергетика лекція I hub 2015
 
Behance Portfolio Review презентація Дмитра Скварського в IHUB Chernihiv
Behance Portfolio Review презентація Дмитра Скварського в IHUB ChernihivBehance Portfolio Review презентація Дмитра Скварського в IHUB Chernihiv
Behance Portfolio Review презентація Дмитра Скварського в IHUB Chernihiv
 
"постійний потік клієнтів на автоматі" презентація в IHUB
"постійний потік клієнтів на автоматі" презентація в IHUB "постійний потік клієнтів на автоматі" презентація в IHUB
"постійний потік клієнтів на автоматі" презентація в IHUB
 
"8 words a day" презентація в IHUB Chernihiv
"8 words a day" презентація в IHUB Chernihiv"8 words a day" презентація в IHUB Chernihiv
"8 words a day" презентація в IHUB Chernihiv
 
Як досягти своїх цілей. Логіка сучасних способів взаємодії.
Як досягти своїх цілей. Логіка сучасних способів взаємодії.Як досягти своїх цілей. Логіка сучасних способів взаємодії.
Як досягти своїх цілей. Логіка сучасних способів взаємодії.
 

Recently uploaded

2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...
Sandy Millin
 
Home assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdfHome assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdf
Tamralipta Mahavidyalaya
 
Overview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with MechanismOverview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with Mechanism
DeeptiGupta154
 
Marketing internship report file for MBA
Marketing internship report file for MBAMarketing internship report file for MBA
Marketing internship report file for MBA
gb193092
 
Embracing GenAI - A Strategic Imperative
Embracing GenAI - A Strategic ImperativeEmbracing GenAI - A Strategic Imperative
Embracing GenAI - A Strategic Imperative
Peter Windle
 
Supporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptxSupporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptx
Jisc
 
Francesca Gottschalk - How can education support child empowerment.pptx
Francesca Gottschalk - How can education support child empowerment.pptxFrancesca Gottschalk - How can education support child empowerment.pptx
Francesca Gottschalk - How can education support child empowerment.pptx
EduSkills OECD
 
How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...
Jisc
 
Unit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdfUnit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdf
Thiyagu K
 
A Strategic Approach: GenAI in Education
A Strategic Approach: GenAI in EducationA Strategic Approach: GenAI in Education
A Strategic Approach: GenAI in Education
Peter Windle
 
Multithreading_in_C++ - std::thread, race condition
Multithreading_in_C++ - std::thread, race conditionMultithreading_in_C++ - std::thread, race condition
Multithreading_in_C++ - std::thread, race condition
Mohammed Sikander
 
Lapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdfLapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdf
Jean Carlos Nunes Paixão
 
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
Nguyen Thanh Tu Collection
 
Chapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptxChapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptx
Mohd Adib Abd Muin, Senior Lecturer at Universiti Utara Malaysia
 
Digital Artifact 2 - Investigating Pavilion Designs
Digital Artifact 2 - Investigating Pavilion DesignsDigital Artifact 2 - Investigating Pavilion Designs
Digital Artifact 2 - Investigating Pavilion Designs
chanes7
 
Synthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptxSynthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptx
Pavel ( NSTU)
 
Welcome to TechSoup New Member Orientation and Q&A (May 2024).pdf
Welcome to TechSoup   New Member Orientation and Q&A (May 2024).pdfWelcome to TechSoup   New Member Orientation and Q&A (May 2024).pdf
Welcome to TechSoup New Member Orientation and Q&A (May 2024).pdf
TechSoup
 
Best Digital Marketing Institute In NOIDA
Best Digital Marketing Institute In NOIDABest Digital Marketing Institute In NOIDA
Best Digital Marketing Institute In NOIDA
deeptiverma2406
 
Guidance_and_Counselling.pdf B.Ed. 4th Semester
Guidance_and_Counselling.pdf B.Ed. 4th SemesterGuidance_and_Counselling.pdf B.Ed. 4th Semester
Guidance_and_Counselling.pdf B.Ed. 4th Semester
Atul Kumar Singh
 
Acetabularia Information For Class 9 .docx
Acetabularia Information For Class 9  .docxAcetabularia Information For Class 9  .docx
Acetabularia Information For Class 9 .docx
vaibhavrinwa19
 

Recently uploaded (20)

2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...
 
Home assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdfHome assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdf
 
Overview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with MechanismOverview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with Mechanism
 
Marketing internship report file for MBA
Marketing internship report file for MBAMarketing internship report file for MBA
Marketing internship report file for MBA
 
Embracing GenAI - A Strategic Imperative
Embracing GenAI - A Strategic ImperativeEmbracing GenAI - A Strategic Imperative
Embracing GenAI - A Strategic Imperative
 
Supporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptxSupporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptx
 
Francesca Gottschalk - How can education support child empowerment.pptx
Francesca Gottschalk - How can education support child empowerment.pptxFrancesca Gottschalk - How can education support child empowerment.pptx
Francesca Gottschalk - How can education support child empowerment.pptx
 
How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...
 
Unit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdfUnit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdf
 
A Strategic Approach: GenAI in Education
A Strategic Approach: GenAI in EducationA Strategic Approach: GenAI in Education
A Strategic Approach: GenAI in Education
 
Multithreading_in_C++ - std::thread, race condition
Multithreading_in_C++ - std::thread, race conditionMultithreading_in_C++ - std::thread, race condition
Multithreading_in_C++ - std::thread, race condition
 
Lapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdfLapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdf
 
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
 
Chapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptxChapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptx
 
Digital Artifact 2 - Investigating Pavilion Designs
Digital Artifact 2 - Investigating Pavilion DesignsDigital Artifact 2 - Investigating Pavilion Designs
Digital Artifact 2 - Investigating Pavilion Designs
 
Synthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptxSynthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptx
 
Welcome to TechSoup New Member Orientation and Q&A (May 2024).pdf
Welcome to TechSoup   New Member Orientation and Q&A (May 2024).pdfWelcome to TechSoup   New Member Orientation and Q&A (May 2024).pdf
Welcome to TechSoup New Member Orientation and Q&A (May 2024).pdf
 
Best Digital Marketing Institute In NOIDA
Best Digital Marketing Institute In NOIDABest Digital Marketing Institute In NOIDA
Best Digital Marketing Institute In NOIDA
 
Guidance_and_Counselling.pdf B.Ed. 4th Semester
Guidance_and_Counselling.pdf B.Ed. 4th SemesterGuidance_and_Counselling.pdf B.Ed. 4th Semester
Guidance_and_Counselling.pdf B.Ed. 4th Semester
 
Acetabularia Information For Class 9 .docx
Acetabularia Information For Class 9  .docxAcetabularia Information For Class 9  .docx
Acetabularia Information For Class 9 .docx
 

SOLID and Clean Code with life project example