Oop design magma rails 2011
Transcript of Oop design magma rails 2011
Isn’t this a design patterns talk?sofftek developer
Skill traciende lenguajes
Las bases que TODOS debemos tener.
Friday, October 14, 2011
Object Oriented Design - Basics
aqui me pararia y me largaba
Friday, October 14, 2011
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
What makes a system complicated?code smell, you feel it
mario c nice code, shit happens eveywhere
same old problems
Friday, October 14, 2011
Rigidity
un cambio implica tocar muchos lugares
Friday, October 14, 2011
Fragility
cambio rompe lugares inesperados
Friday, October 14, 2011
Viscosity
dificil hacer la cosa correcta
de diseño
de ambiente
Friday, October 14, 2011
Immobility
duplicidad
no puedes reutilizar componentes
componentes utiles, pero separar es muy complicado
Friday, October 14, 2011
Unnecessary complexity
mas de lo que ocupas
anticipas a requerimientos
hard to understand
Friday, October 14, 2011
Unnecessary duplicity
resultado de reutilizar codigo copy paste
Friday, October 14, 2011
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
• 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
Small components design principles
small building blocks
small shapes
Pequeñas formas -> grandes diseños
Bellos?
Friday, October 14, 2011
Single Responsibility (SR)
Friday, October 14, 2011
SR- How do I achieve it?
Friday, October 14, 2011
SR - Analyze your object
• Delegate
• Encapsulate what changes
Friday, October 14, 2011
SR - Delegate?
Friday, October 14, 2011
SR - Delegate! in ruby
Friday, October 14, 2011
SR - Delegate! in ruby
Friday, October 14, 2011
SR - Delegate! with rails
Friday, October 14, 2011
SR - Delegate! with rails
Friday, October 14, 2011
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
OC - Open for extensionclosed for modification
Friday, October 14, 2011
OC - Don not reopen an object
Friday, October 14, 2011
OP - Encapsulate and extend it
Friday, October 14, 2011
OC - Composition over inheritance
Friday, October 14, 2011
OC - Composition implemented
Friday, October 14, 2011
Dependency Inversion (DI)
Friday, October 14, 2011
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
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
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
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
Observer
• THINK: monitoring behavior
Friday, October 14, 2011
Observer - An observer
Friday, October 14, 2011
Observer - The observed
Friday, October 14, 2011
Strategy
• THINK: Interchangeable algorithms
Friday, October 14, 2011
Strategycomo llegas aqui? cuando un metodo ya tiene varios branchings
Friday, October 14, 2011
Strategy - Interchangeable algorithms
como llegas aqui? cuando un metodo ya tiene varios branchings
Friday, October 14, 2011
Proxy
• THINK: Wrapping object behavior, forward calls
Friday, October 14, 2011
Proxy
Friday, October 14, 2011
Template
• THINK: Predefined steps
Friday, October 14, 2011
Template- Required?
Friday, October 14, 2011
Template- Implemented
Friday, October 14, 2011
Decorator
• THINK: Present new content based on original content
Friday, October 14, 2011
Decorator - required?
Friday, October 14, 2011
Decorator - implemented
Friday, October 14, 2011
THE END
Friday, October 14, 2011
Conclusion
• Follow damn simple principles
• Do not program upon design patterns, let them arise by themselves
• Refactor to design patterns
Friday, October 14, 2011
References - 1
Friday, October 14, 2011
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
References - 3
Friday, October 14, 2011
References - 4
pregunta para ustedes como mantienes el diseño dia tras dia?
boy scout ruletddrefactor all the fucking time
Friday, October 14, 2011