SOLID for AdultsPaweł KlimczykGemotial 2016
Process, context and abstraction
About me• Software engineer• Running Gemotial Software Studio • WrocNET co-organizer • Blog http://blog.klimczyk.pl• Contact:• Twitter @pwlklm• Mail: [email protected]
What is OOP ?
•Abstraction•Encapsulation•Inheritance•Polymorphism
SOLID – the beginning
Michael Feathers Robert C.Martin
Year ~2000
OOP (r)evolution
•Simula 67, Smalltalk •Ada, Lisp•C#, Java
Technical debt trap
•Hard to extend rotten code•The longer we wait to remove the code smells, the more it will cost•Harder to introduce to new programmers in team
Occam's razor principleOccam's razor is a problem-solving principle devised by William of Ockham. The principle states that among competing hypotheses, the one with the fewest assumptions should be selected. Other, more complicated solutions may ultimately prove correct, but—in the absence of certainty—the fewer assumptions that are made, the better.
SOLID•Single Responsibility Principle (SRP)•Open-Closed Principle (OCP)•Liskov Substitution Principle (LSP)•Interface Segregation Principle (ISP)•Dependency Inversion Principle (DIP)
Single Responsibility Principle (SRP)
A class or similar unit of code should have one responsibility only and, therefore, only one reason to change.
Single Responsibility Principle (SRP)
Open-Closed Principle (OCP)
You should be able to extend a classes behavior, without modifying it.
Open-Closed Principle (OCP)
Liskov Substitution Principle (LSP)
Derived classes must be substitutable for their base classes.
Liskov Substitution Principle (LSP)
Interface Segregation Principle (ISP)
Make fine grained interfaces that are client specific.Clients should not be forced to depend upon interfaces that
they don't use.
Interface Segregation Principle (ISP)
Dependency Inversion Principle (DIP)
Depend on abstractions, not on concretions.High level modules should not depend upon low level modules
and abstractions should not depend upon details.
Dependency Inversion Principle (DIP)
Other principles
•Design Patterns (GoF)•Keep It Simple Stupid (KISS)•You Ain’t Gonna Need It (YAGNI)•Don’t Repeat Yourself (DRY)
Adults
Process, Context and Abstraction
Perspectives
•Business •Technology•Art
Business perspective
Business perspective
•Time to market•Quality, time and money triangle•Legal & Security
Technology perspective
Technology perspective
•New frameworks•New languages•New coding techniques•New tools•New new new ………
Art perspective
Art perspective
•Pure and beautiful code•Passion•Poetry (The Art of Digital Code Creation)
Perspectives balance
“”
"Any organization that designs a system (defined more broadly here than just information systems) will inevitably
produce a design whose structure is a copy of the organization's communication
structure." Conway, 1968 Conway's Law
"If you have three developers writing a UI you will get three ways of doing everything (mouse click, menu item, short-cut key)
"If you have four developers writing a compiler you will get a four pass compiler"
Crime scene
Crime scenecode cohesion and module references
(NDepend)
Crime scene code size, cyclomatic complexity (NDepend)
Crime scene code size, God&Brain (CodeCity)
Crime scene - Hotspots
Files in VCS that changes very often
Crime scene Unit tests vs implementation details
A B C
Functional codeTests code
Crime scenechanged files in commit/branch
One logical change results in multiple technical changes
Process, Context and Abstraction - DDD solution
DDD<<ZNAJDZ GRAFIKE Z CHMURA DDD>>
Maintenance – 60% - 90% of costs
This is where the real costs are
Key takeaways
•KISS •Occam's razor
Key outcome – Code sample
Actions for you
•Don’t stop questioning•Can you do better?•Less is better
References
• http://objectmentor.com/Images/photo_feathers.jpg• http://
upload.wikimedia.org/wikipedia/commons/thumb/e/ee/Robert_Cecil_Martin.png/220px-Robert_Cecil_Martin.png• http://www.inf.usi.ch/faculty/lanza/Downloads/Wett2008b.pdf
• http://www.butunclebob.com/ArticleS.UncleBob.PrinciplesOfOod• SOLID examples:• https://msdn.microsoft.com/en-us/magazine/dn683797.aspx
Q&A
Thank you!