Solid as OOP abstraction

24
SOLID as OOP abstraction Paweł Klimczyk Gemotial 2016

Transcript of Solid as OOP abstraction

Page 1: Solid as OOP abstraction

SOLID as OOP abstraction

Paweł KlimczykGemotial 2016

Page 2: Solid as OOP abstraction

About me

•Software engineer•Running Gemotial Software Studio •Co-organizer of WrocNET•Blog: http://blog.klimczyk.pl•E-mail: [email protected]•Twitter: @pwlklm•GitHub: pawelklimczyk

Page 3: Solid as OOP abstraction

Software Quality/SOLIDjobesto.comC#/.NET/BizTalknetdevelopers.pl BJJ

What I do

Page 4: Solid as OOP abstraction

What is OOP ?

•Abstraction•Encapsulation•Inheritance•Polymorphism

Page 5: Solid as OOP abstraction

OOP (r)evolution

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

Pawel Klimczyk
Ole-Johana Dahl and Kristen Nygaard
Page 6: Solid as OOP abstraction

OOP bad habits- Code Smells

• Duplicate Code• Long Method• Comments• Long Parameter List• Large Class• Switch Statements• Parallel Inheritance

Hierarchies• Conditional Complexity• Combinitorial Explosion• Uncommunicative Name• Dead Code• Inconsistent Names• Temporary Field

Page 7: Solid as OOP abstraction

OOP bad habits - Design Smells• Alternative Classes with

Different Interfaces• Primitive ObsessionData

Class• Data Clumps• Refused Bequest• Inappropriate Intimacy• Indecent Exposure• Feature Envy

• Lazy Class• Message Chains• Middle Man• Divergent Change• Shotgun Surgery • Parallel Inheritance

Hierarchies• Incomplete Library Class• Solution Sprawl

Page 8: Solid as OOP abstraction

Technical debt trap

•Hard to extend rotten code•The longer we wait to remove the smells, the more it will cost

Page 9: Solid as OOP abstraction

SOLID – the beginning

Michael Feathers Robert C.Martin

Year ~2000

Page 10: Solid as OOP abstraction

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 11: Solid as OOP abstraction

SOLID

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

Page 12: Solid as OOP abstraction

Single Responsibility Principle (SRP)

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

Page 13: Solid as OOP abstraction

Single Responsibility Principle (SRP)

Page 14: Solid as OOP abstraction

Open-Closed Principle (OCP)

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

Page 15: Solid as OOP abstraction

Open-Closed Principle (OCP)

Page 16: Solid as OOP abstraction

Liskov Substitution Principle (LSP)

Derived classes must be substitutable for their base classes.

Page 17: Solid as OOP abstraction

Liskov Substitution Principle (LSP)

Page 18: Solid as OOP abstraction

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 19: Solid as OOP abstraction

Interface Segregation Principle (ISP)

Page 20: Solid as OOP abstraction

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 21: Solid as OOP abstraction

Dependency Inversion Principle (DIP)

Page 22: Solid as OOP abstraction

Other principles

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

Page 23: Solid as OOP abstraction

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.butunclebob.com/ArticleS.UncleBob.PrinciplesOfOod• SOLID examples:• https://msdn.microsoft.com/en-us/magazine/dn683797.aspx

Page 24: Solid as OOP abstraction

Q&A