solid for adults

44
SOLID for Adults Paweł Klimczyk Gemotial 2016 Process, context and abstraction

Upload: pawel-klimczyk

Post on 11-Jan-2017

26 views

Category:

Software


0 download

TRANSCRIPT

Page 1: SOLID for Adults

SOLID for AdultsPaweł KlimczykGemotial 2016

Process, context and abstraction

Page 2: SOLID for Adults

About me• Software engineer• Running Gemotial Software Studio • WrocNET co-organizer • Blog http://blog.klimczyk.pl• Contact:• Twitter @pwlklm• Mail: [email protected]

Page 3: SOLID for Adults

What is OOP ?

•Abstraction•Encapsulation•Inheritance•Polymorphism

Page 4: SOLID for Adults

SOLID – the beginning

Michael Feathers Robert C.Martin

Year ~2000

Page 5: SOLID for Adults

OOP (r)evolution

•Simula 67, Smalltalk •Ada, Lisp•C#, Java

Page 6: SOLID for Adults

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

Page 7: SOLID for Adults

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.

Page 8: SOLID for Adults

SOLID•Single Responsibility Principle (SRP)•Open-Closed Principle (OCP)•Liskov Substitution Principle (LSP)•Interface Segregation Principle (ISP)•Dependency Inversion Principle (DIP)

Page 9: SOLID for Adults

Single Responsibility Principle (SRP)

A class or similar unit of code should have one responsibility only and, therefore, only one reason to change.

Page 10: SOLID for Adults

Single Responsibility Principle (SRP)

Page 11: SOLID for Adults

Open-Closed Principle (OCP)

You should be able to extend a classes behavior, without modifying it.

Page 12: SOLID for Adults

Open-Closed Principle (OCP)

Page 13: SOLID for Adults

Liskov Substitution Principle (LSP)

Derived classes must be substitutable for their base classes.

Page 14: SOLID for Adults

Liskov Substitution Principle (LSP)

Page 15: SOLID for Adults

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.

Page 16: SOLID for Adults

Interface Segregation Principle (ISP)

Page 17: SOLID for Adults

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.

Page 18: SOLID for Adults

Dependency Inversion Principle (DIP)

Page 19: SOLID for Adults

Other principles

•Design Patterns (GoF)•Keep It Simple Stupid (KISS)•You Ain’t Gonna Need It (YAGNI)•Don’t Repeat Yourself (DRY)

Page 20: SOLID for Adults

Adults

Process, Context and Abstraction

Page 21: SOLID for Adults

Perspectives

•Business •Technology•Art

Page 22: SOLID for Adults

Business perspective

Page 23: SOLID for Adults

Business perspective

•Time to market•Quality, time and money triangle•Legal & Security

Page 24: SOLID for Adults

Technology perspective

Page 25: SOLID for Adults

Technology perspective

•New frameworks•New languages•New coding techniques•New tools•New new new ………

Page 26: SOLID for Adults

Art perspective

Page 27: SOLID for Adults

Art perspective

•Pure and beautiful code•Passion•Poetry (The Art of Digital Code Creation)

Page 28: SOLID for Adults

Perspectives balance

Page 29: SOLID for Adults

“”

"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"

Page 30: SOLID for Adults

Crime scene

Page 31: SOLID for Adults

Crime scenecode cohesion and module references

(NDepend)

Page 32: SOLID for Adults

Crime scene code size, cyclomatic complexity (NDepend)

Page 33: SOLID for Adults

Crime scene code size, God&Brain (CodeCity)

Page 34: SOLID for Adults

Crime scene - Hotspots

Files in VCS that changes very often

Page 35: SOLID for Adults

Crime scene Unit tests vs implementation details

A B C

Functional codeTests code

Page 36: SOLID for Adults

Crime scenechanged files in commit/branch

One logical change results in multiple technical changes

Page 37: SOLID for Adults

Process, Context and Abstraction - DDD solution

DDD<<ZNAJDZ GRAFIKE Z CHMURA DDD>>

Page 38: SOLID for Adults

Maintenance – 60% - 90% of costs

This is where the real costs are

Page 39: SOLID for Adults

Key takeaways

•KISS •Occam's razor

Page 40: SOLID for Adults

Key outcome – Code sample

Page 41: SOLID for Adults

Actions for you

•Don’t stop questioning•Can you do better?•Less is better

Page 42: SOLID for Adults

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

Page 43: SOLID for Adults

Q&A

Page 44: SOLID for Adults

Thank you!