Download - Oop design magma rails 2011
![Page 1: Oop design magma rails 2011](https://reader033.vdocument.in/reader033/viewer/2022052823/55519349b4c905013a8b461d/html5/thumbnails/1.jpg)
Isn’t this a design patterns talk?sofftek developer
Skill traciende lenguajes
Las bases que TODOS debemos tener.
Friday, October 14, 2011
![Page 2: Oop design magma rails 2011](https://reader033.vdocument.in/reader033/viewer/2022052823/55519349b4c905013a8b461d/html5/thumbnails/2.jpg)
Object Oriented Design - Basics
aqui me pararia y me largaba
Friday, October 14, 2011
![Page 3: Oop design magma rails 2011](https://reader033.vdocument.in/reader033/viewer/2022052823/55519349b4c905013a8b461d/html5/thumbnails/3.jpg)
ME
• Emmanuel Delgado
• Ingeniero de Software para Crowd Interactive
• UAA, INEGI, Softtek
• PHP, Perl, Javascript, Java, Ruby
• Apasionadazo
• @chischaschos
Como me siento?
Con quienes he colaborado?
En que cosas te apasionas?
Friday, October 14, 2011
![Page 4: Oop design magma rails 2011](https://reader033.vdocument.in/reader033/viewer/2022052823/55519349b4c905013a8b461d/html5/thumbnails/4.jpg)
What makes a system complicated?code smell, you feel it
mario c nice code, shit happens eveywhere
same old problems
Friday, October 14, 2011
![Page 5: Oop design magma rails 2011](https://reader033.vdocument.in/reader033/viewer/2022052823/55519349b4c905013a8b461d/html5/thumbnails/5.jpg)
Rigidity
un cambio implica tocar muchos lugares
Friday, October 14, 2011
![Page 6: Oop design magma rails 2011](https://reader033.vdocument.in/reader033/viewer/2022052823/55519349b4c905013a8b461d/html5/thumbnails/6.jpg)
Fragility
cambio rompe lugares inesperados
Friday, October 14, 2011
![Page 7: Oop design magma rails 2011](https://reader033.vdocument.in/reader033/viewer/2022052823/55519349b4c905013a8b461d/html5/thumbnails/7.jpg)
Viscosity
dificil hacer la cosa correcta
de diseño
de ambiente
Friday, October 14, 2011
![Page 8: Oop design magma rails 2011](https://reader033.vdocument.in/reader033/viewer/2022052823/55519349b4c905013a8b461d/html5/thumbnails/8.jpg)
Immobility
duplicidad
no puedes reutilizar componentes
componentes utiles, pero separar es muy complicado
Friday, October 14, 2011
![Page 9: Oop design magma rails 2011](https://reader033.vdocument.in/reader033/viewer/2022052823/55519349b4c905013a8b461d/html5/thumbnails/9.jpg)
Unnecessary complexity
mas de lo que ocupas
anticipas a requerimientos
hard to understand
Friday, October 14, 2011
![Page 10: Oop design magma rails 2011](https://reader033.vdocument.in/reader033/viewer/2022052823/55519349b4c905013a8b461d/html5/thumbnails/10.jpg)
Unnecessary duplicity
resultado de reutilizar codigo copy paste
Friday, October 14, 2011
![Page 11: Oop design magma rails 2011](https://reader033.vdocument.in/reader033/viewer/2022052823/55519349b4c905013a8b461d/html5/thumbnails/11.jpg)
Opacity
la imagen es la misma
tendencia dificil de entender
codigo puede ser claro y legible
requieres esfuerzo constante para seguir siendo leguible
Friday, October 14, 2011
![Page 12: Oop design magma rails 2011](https://reader033.vdocument.in/reader033/viewer/2022052823/55519349b4c905013a8b461d/html5/thumbnails/12.jpg)
• Rigidity
• Fragility
• Viscosity
• Immobility
• Unnecessary duplicity and complexity
• Opacity
Rotten system usual smells
ocurren poco a poco un commit a la vez
Friday, October 14, 2011
![Page 13: Oop design magma rails 2011](https://reader033.vdocument.in/reader033/viewer/2022052823/55519349b4c905013a8b461d/html5/thumbnails/13.jpg)
Small components design principles
small building blocks
small shapes
Pequeñas formas -> grandes diseños
Bellos?
Friday, October 14, 2011
![Page 14: Oop design magma rails 2011](https://reader033.vdocument.in/reader033/viewer/2022052823/55519349b4c905013a8b461d/html5/thumbnails/14.jpg)
Single Responsibility (SR)
Friday, October 14, 2011
![Page 15: Oop design magma rails 2011](https://reader033.vdocument.in/reader033/viewer/2022052823/55519349b4c905013a8b461d/html5/thumbnails/15.jpg)
SR- How do I achieve it?
Friday, October 14, 2011
![Page 16: Oop design magma rails 2011](https://reader033.vdocument.in/reader033/viewer/2022052823/55519349b4c905013a8b461d/html5/thumbnails/16.jpg)
SR - Analyze your object
• Delegate
• Encapsulate what changes
Friday, October 14, 2011
![Page 17: Oop design magma rails 2011](https://reader033.vdocument.in/reader033/viewer/2022052823/55519349b4c905013a8b461d/html5/thumbnails/17.jpg)
SR - Delegate?
Friday, October 14, 2011
![Page 18: Oop design magma rails 2011](https://reader033.vdocument.in/reader033/viewer/2022052823/55519349b4c905013a8b461d/html5/thumbnails/18.jpg)
SR - Delegate! in ruby
Friday, October 14, 2011
![Page 19: Oop design magma rails 2011](https://reader033.vdocument.in/reader033/viewer/2022052823/55519349b4c905013a8b461d/html5/thumbnails/19.jpg)
SR - Delegate! in ruby
Friday, October 14, 2011
![Page 20: Oop design magma rails 2011](https://reader033.vdocument.in/reader033/viewer/2022052823/55519349b4c905013a8b461d/html5/thumbnails/20.jpg)
SR - Delegate! with rails
Friday, October 14, 2011
![Page 21: Oop design magma rails 2011](https://reader033.vdocument.in/reader033/viewer/2022052823/55519349b4c905013a8b461d/html5/thumbnails/21.jpg)
SR - Delegate! with rails
Friday, October 14, 2011
![Page 22: Oop design magma rails 2011](https://reader033.vdocument.in/reader033/viewer/2022052823/55519349b4c905013a8b461d/html5/thumbnails/22.jpg)
SR - Encapsulate what changes
+------------------------------------+---------------+| file_path | times_changed |+------------------------------------+---------------+| lib/churn/churn_calculator.rb | 14 || README.rdoc | 7 || lib/tasks/churn_tasks.rb | 6 || Rakefile | 6 || lib/churn/git_analyzer.rb | 4 || VERSION | 4 || test/test_helper.rb | 4 || test/unit/churn_calculator_test.rb | 3 || test/churn_test.rb | 3 |+------------------------------------+---------------+
interview question
Que es encapsular, ejemplo ftp uploader
como ayuda churn, idealmente los No picos
Friday, October 14, 2011
![Page 23: Oop design magma rails 2011](https://reader033.vdocument.in/reader033/viewer/2022052823/55519349b4c905013a8b461d/html5/thumbnails/23.jpg)
OC - Open for extensionclosed for modification
Friday, October 14, 2011
![Page 24: Oop design magma rails 2011](https://reader033.vdocument.in/reader033/viewer/2022052823/55519349b4c905013a8b461d/html5/thumbnails/24.jpg)
OC - Don not reopen an object
Friday, October 14, 2011
![Page 25: Oop design magma rails 2011](https://reader033.vdocument.in/reader033/viewer/2022052823/55519349b4c905013a8b461d/html5/thumbnails/25.jpg)
OP - Encapsulate and extend it
Friday, October 14, 2011
![Page 26: Oop design magma rails 2011](https://reader033.vdocument.in/reader033/viewer/2022052823/55519349b4c905013a8b461d/html5/thumbnails/26.jpg)
OC - Composition over inheritance
Friday, October 14, 2011
![Page 27: Oop design magma rails 2011](https://reader033.vdocument.in/reader033/viewer/2022052823/55519349b4c905013a8b461d/html5/thumbnails/27.jpg)
OC - Composition implemented
Friday, October 14, 2011
![Page 28: Oop design magma rails 2011](https://reader033.vdocument.in/reader033/viewer/2022052823/55519349b4c905013a8b461d/html5/thumbnails/28.jpg)
Dependency Inversion (DI)
Friday, October 14, 2011
![Page 29: Oop design magma rails 2011](https://reader033.vdocument.in/reader033/viewer/2022052823/55519349b4c905013a8b461d/html5/thumbnails/29.jpg)
DI - What is a dependency?dependencia agrega responsabilidades
responsabilidad da razones para cambiar
vas a tener que hacer cambios
entre menos mejor, asi gastas mas tiempo creando codigo obra d arte
Friday, October 14, 2011
![Page 30: Oop design magma rails 2011](https://reader033.vdocument.in/reader033/viewer/2022052823/55519349b4c905013a8b461d/html5/thumbnails/30.jpg)
DI - Depend upon abstractions
Si tu clase emplea servicios externos, o tiene muchas librerias requeridas, o ves demasiadas constantes, utilizalas tan tarde como puedas.
Friday, October 14, 2011
![Page 31: Oop design magma rails 2011](https://reader033.vdocument.in/reader033/viewer/2022052823/55519349b4c905013a8b461d/html5/thumbnails/31.jpg)
Basic suggestions
• Only one responsibility per object
• Encapsulate what changes
• Depend upon abstractions
• Delegate responsibilities
• Composition over inheritance
• Extend components, do not reopen them
Friday, October 14, 2011
![Page 32: Oop design magma rails 2011](https://reader033.vdocument.in/reader033/viewer/2022052823/55519349b4c905013a8b461d/html5/thumbnails/32.jpg)
Afterwards common shapes will arise
patrones de diseño
alguien identifico problemas comunes
formas se repiten
evita crear patrones hasta el ultimo momento
Friday, October 14, 2011
![Page 33: Oop design magma rails 2011](https://reader033.vdocument.in/reader033/viewer/2022052823/55519349b4c905013a8b461d/html5/thumbnails/33.jpg)
Observer
• THINK: monitoring behavior
Friday, October 14, 2011
![Page 34: Oop design magma rails 2011](https://reader033.vdocument.in/reader033/viewer/2022052823/55519349b4c905013a8b461d/html5/thumbnails/34.jpg)
Observer - An observer
Friday, October 14, 2011
![Page 35: Oop design magma rails 2011](https://reader033.vdocument.in/reader033/viewer/2022052823/55519349b4c905013a8b461d/html5/thumbnails/35.jpg)
Observer - The observed
Friday, October 14, 2011
![Page 36: Oop design magma rails 2011](https://reader033.vdocument.in/reader033/viewer/2022052823/55519349b4c905013a8b461d/html5/thumbnails/36.jpg)
Strategy
• THINK: Interchangeable algorithms
Friday, October 14, 2011
![Page 37: Oop design magma rails 2011](https://reader033.vdocument.in/reader033/viewer/2022052823/55519349b4c905013a8b461d/html5/thumbnails/37.jpg)
Strategycomo llegas aqui? cuando un metodo ya tiene varios branchings
Friday, October 14, 2011
![Page 38: Oop design magma rails 2011](https://reader033.vdocument.in/reader033/viewer/2022052823/55519349b4c905013a8b461d/html5/thumbnails/38.jpg)
Strategy - Interchangeable algorithms
como llegas aqui? cuando un metodo ya tiene varios branchings
Friday, October 14, 2011
![Page 39: Oop design magma rails 2011](https://reader033.vdocument.in/reader033/viewer/2022052823/55519349b4c905013a8b461d/html5/thumbnails/39.jpg)
Proxy
• THINK: Wrapping object behavior, forward calls
Friday, October 14, 2011
![Page 40: Oop design magma rails 2011](https://reader033.vdocument.in/reader033/viewer/2022052823/55519349b4c905013a8b461d/html5/thumbnails/40.jpg)
Proxy
Friday, October 14, 2011
![Page 41: Oop design magma rails 2011](https://reader033.vdocument.in/reader033/viewer/2022052823/55519349b4c905013a8b461d/html5/thumbnails/41.jpg)
Template
• THINK: Predefined steps
Friday, October 14, 2011
![Page 42: Oop design magma rails 2011](https://reader033.vdocument.in/reader033/viewer/2022052823/55519349b4c905013a8b461d/html5/thumbnails/42.jpg)
Template- Required?
Friday, October 14, 2011
![Page 43: Oop design magma rails 2011](https://reader033.vdocument.in/reader033/viewer/2022052823/55519349b4c905013a8b461d/html5/thumbnails/43.jpg)
Template- Implemented
Friday, October 14, 2011
![Page 44: Oop design magma rails 2011](https://reader033.vdocument.in/reader033/viewer/2022052823/55519349b4c905013a8b461d/html5/thumbnails/44.jpg)
Decorator
• THINK: Present new content based on original content
Friday, October 14, 2011
![Page 45: Oop design magma rails 2011](https://reader033.vdocument.in/reader033/viewer/2022052823/55519349b4c905013a8b461d/html5/thumbnails/45.jpg)
Decorator - required?
Friday, October 14, 2011
![Page 46: Oop design magma rails 2011](https://reader033.vdocument.in/reader033/viewer/2022052823/55519349b4c905013a8b461d/html5/thumbnails/46.jpg)
Decorator - implemented
Friday, October 14, 2011
![Page 47: Oop design magma rails 2011](https://reader033.vdocument.in/reader033/viewer/2022052823/55519349b4c905013a8b461d/html5/thumbnails/47.jpg)
THE END
Friday, October 14, 2011
![Page 48: Oop design magma rails 2011](https://reader033.vdocument.in/reader033/viewer/2022052823/55519349b4c905013a8b461d/html5/thumbnails/48.jpg)
Conclusion
• Follow damn simple principles
• Do not program upon design patterns, let them arise by themselves
• Refactor to design patterns
Friday, October 14, 2011
![Page 49: Oop design magma rails 2011](https://reader033.vdocument.in/reader033/viewer/2022052823/55519349b4c905013a8b461d/html5/thumbnails/49.jpg)
References - 1
Friday, October 14, 2011
![Page 50: Oop design magma rails 2011](https://reader033.vdocument.in/reader033/viewer/2022052823/55519349b4c905013a8b461d/html5/thumbnails/50.jpg)
References - 2• CHURN: https://github.com/danmayer/churn
• http://vimeo.com/12350535
• http://vimeo.com/26330100
• http://confreaks.net/videos/257-larubyconf2009-the-building-blocks-of-modularity
• https://www.destroyallsoftware.com/screencasts
Friday, October 14, 2011
![Page 51: Oop design magma rails 2011](https://reader033.vdocument.in/reader033/viewer/2022052823/55519349b4c905013a8b461d/html5/thumbnails/51.jpg)
References - 3
Friday, October 14, 2011
![Page 52: Oop design magma rails 2011](https://reader033.vdocument.in/reader033/viewer/2022052823/55519349b4c905013a8b461d/html5/thumbnails/52.jpg)
References - 4
pregunta para ustedes como mantienes el diseño dia tras dia?
boy scout ruletddrefactor all the fucking time
Friday, October 14, 2011