45
S.O.L.I.D. Python

Python SOLID

Embed Size (px)

DESCRIPTION

 

Citation preview

Page 1: Python SOLID

S.O.L.I.D. Python

Page 2: Python SOLID

Alea Soluciones Bifer Team

Page 3: Python SOLID

@eferro@pasku1 @apa42

@nestorsalceda

Page 4: Python SOLID

Usual OO Systems

RigidFragile

ImmobileViscous

Page 5: Python SOLID
Page 6: Python SOLID

Why S.O.L.I.D. principles?

To create easy to maintain OO systemsImprove reusability

Easy testing

Page 7: Python SOLID

For creating

Clean Code

Page 8: Python SOLID

It's all about money

Page 9: Python SOLID
Page 10: Python SOLID

S.O.L.I.DSRP - Single responsibility principleDIP - Dependency inversion principleOCP - Open/closed principleLSP - Liskov substitution principleISP - Interface segregation principle

Page 11: Python SOLID

PrinciplesNot Rules

Page 12: Python SOLID
Page 13: Python SOLID

Car wash service car wash job when the car enters in the car wash ✓ it registers a job customer notification when service completed ✓ it notifies the customer reporting when client report requested ✓ it shows all wash services for that customer

3 examples ran in 0.0178 seconds

Page 14: Python SOLID
Page 15: Python SOLID
Page 16: Python SOLID
Page 17: Python SOLID
Page 18: Python SOLID

…Some refactors / versions later

Page 19: Python SOLID
Page 20: Python SOLID
Page 21: Python SOLID

Depend upon Abstractions. Do not depend upon concretion

Page 22: Python SOLID

Compilation / Startup time dependency

from <package> import module

Page 23: Python SOLID

Runtime dependency

self.collaborator.message()

Page 24: Python SOLID
Page 25: Python SOLID

Global State ProblemImplicit dependency problemConcrete API

Page 26: Python SOLID

No dependency injectionImplicit dependency problem

Concrete API

Page 27: Python SOLID
Page 28: Python SOLID
Page 29: Python SOLID
Page 30: Python SOLID
Page 31: Python SOLID
Page 32: Python SOLID
Page 33: Python SOLID

Duck Typing Approved!!!

Page 34: Python SOLID
Page 35: Python SOLID

Liskov Substitutionprinciple violation

Page 36: Python SOLID

Python don't force type inheritanceFor API implementation

(So, for reuse code, prefer Composition)

Page 37: Python SOLID

Derived types must be completely substitutable for their base types

Page 38: Python SOLID
Page 39: Python SOLID

It isn't so important

Page 40: Python SOLID

A narrow interface is a better interface

Page 41: Python SOLID

SOLID Motivational Posters, by Derick Baileyhttp://lostechies.com/derickbailey/2009/02/11/solid-development-principles-in-motivational-pictures/

Page 42: Python SOLID

car_wash code examplehttps://github.com/aleasoluciones/car_wash

SOLID definition (at wikipedia)http://en.wikipedia.org/wiki/SOLID_(object-oriented_design)

Getting a SOLID start (Uncle Bob)http://butunclebob.com/ArticleS.UncleBob.PrinciplesOfOod

Video SOLID Object Oriented Design (Sandi Metz)http://www.confreaks.com/videos/240-goruco2009-solid-object-oriented-design

Page 43: Python SOLID
Page 44: Python SOLID
Page 45: Python SOLID

Thanks !!!@eferro

@pasku1 @apa42

@nestorsalceda