SOLID and Better Design

Preview:

DESCRIPTION

SOLID Principles for Better Software Design

Citation preview

SOLIDand Better Design

Photo by Roy Higson. http://www.fotopedia.com/items/roytheboy-Q13G6ugLM0I

SOLIDand Better Design

Toni TassaniMarch 2013

Writing Software is not hard

You spend more time Reading and Modifying it

Design Smells

1. Rigidity2. Fragility3. Immobility4. Viscosity5. Needless Complexity6. Needless repetition7. Opacity

Photo by Elaine Adolfo http://www.fotopedia.com/items/flickr-469125880

Design Smells

1. Rigidity2. Fragility3. Immobility4. Viscosity5. Needless Complexity6. Needless repetition7. Opacity

The system is hard to change because every change forces many other changes to other parts of the system.

Design Smells

1. Rigidity2. Fragility3. Immobility4. Viscosity5. Needless Complexity6. Needless repetition7. Opacity

Changes cause the system to break in places that have no conceptual relationship to the part that was changed.

Design Smells

1. Rigidity2. Fragility3. Immobility4. Viscosity5. Needless Complexity6. Needless repetition7. Opacity

It is hard to disentangle the system into components that ca be reused in other systems.

Design Smells

1. Rigidity2. Fragility3. Immobility4. Viscosity5. Needless Complexity6. Needless repetition7. Opacity

Doing things right is harder than doind things wrong.

Design Smells

1. Rigidity2. Fragility3. Immobility4. Viscosity5. Needless Complexity6. Needless repetition7. Opacity

The design contains infrastructure that adds no direct benefit.

Design Smells

1. Rigidity2. Fragility3. Immobility4. Viscosity5. Needless Complexity6. Needless repetition7. Opacity

The design contains repeating structures that could be unified under a single abstraction.

Design Smells

1. Rigidity2. Fragility3. Immobility4. Viscosity5. Needless Complexity6. Needless repetition7. Opacity

It is hard to read and understand. It does not express its intent well.

• Cohesion– All responsibilites of a module should be

related and focused.

• Coupling– How much a module depends upon

others

S.O.L.I.D.

• Single Responsibility• Open Closed• Liskov Substitution• Interface Segregation• Dependency Inversion

Photo by Jean Christophe Prunet http://www.fotopedia.com/items/_avPIZmqM3w-vdSxZGLACsg

Single Responsibility Principle

• One class should have only one reason to change.

• One responsability, one reason to change

Open Closed Principle

• Open for extension• Closed for modification

• Design modules to never change.• A change should impact only one

module.• Abstraction

Liskov Substitution Principle

• If you use a class, you should be able to use its base class.

Interface Segregation Principle

• Clients should not be obliged to depend upon interfaces they not use

Dependency Injection Principle

• Higher level modules should not depend upon low level modules

4 rules of simple design

1. Runs all the tests2. Contains no duplication3. Expresses the intent of the

programmer4. Minimizes the number of classes

and methods

Kent Beck

Summary

Read More

References

• http://www.slideshare.net/JuanjoFuchs/solid-cmo-lo-aplico-a-mi-cdigo

• SOLID Development by Chris Deweese http://www.slideshare.net/cdeweese/solid-development

• SOLID Design Principles by Bruno Bossola http://www.slideshare.net/bbossola/geecon09-solid

• Solid Development Practices in Motivational Pictures http://lostechies.com/derickbailey/2009/02/11/solid-development-principles-in-motivational-pictures/

Toni Tassani

Toni Tassani

@atassani

http://alapamui.blogspot.com

Barcelona -

Moltes Gràcies(Thank you very much)