class: center, middle # SOLID & concrete .b[[@abelar_s](https://twitter.com/abelar_s) - [@ParisRB](https://twitter.com/parisrb) - [@RailsGirlsParis](https://twitter.com/railsgirlsparis)] [maitre-du-monde.fr](maitre-du-monde.fr) .contrib[[Contribute to this talk on GitHub!](https://github.com/abelards/abelards.github.com/edit/master/talks/SOLID.html)] ??? --- class: center, middle # SOLID & concrete ## SRP + OCP + LSP + ISP + DIP .b[[@abelar_s](https://twitter.com/abelar_s) - [@ParisRB](https://twitter.com/parisrb) - [@RailsGirlsParis](https://twitter.com/railsgirlsparis)] [maitre-du-monde.fr](maitre-du-monde.fr) .contrib[[Contribute to this talk on GitHub!](https://github.com/abelards/abelards.github.com/edit/master/talks/SOLID.html)] ??? --- class: center, java # SRP 4 JAVA ## Single Responsibility Principle "A class should only have a single responsibility" --- class: center, rationale # SRP Rationale ## Single Responsibility Principle "A responsibility is a reason to change" --- class: center, ruby # SRP 4 RUBY ## Single Responsibility Principle - `check_state`, `to_state_x` # also sends mail - right_state? - send_email - trigger: send_email_when_right_state ??? Triggers: when I create an order in the right state, send an email. --- class: center, koans # SRP Koäns ## Single Responsibility Principle - [175 Flat Shark](http://thecodelesscode.com/case/175) - [83 Consequences](http://thecodelesscode.com/case/83) - [117 Bareback](http://thecodelesscode.com/case/117) - [167 Back to Basics](http://thecodelesscode.com/case/167) --- class: java # OCP 4 JAVA ## Open-Closed Principle "Software entities … should be open for extension, but closed for modification." Abstract classes all the way down. --- class: rationale # OCP Rationale ## Open-Closed Principle Isolation, tests, change. Libraries' reuse, adding meaning to basic structures... --- class: ruby # OCP 4 RUBY ## Open-Closed Principle OMG we're Rubyists! o_O; JK we just limit on monkeypatching, metaprog, and... it's message passing time! <3 --- class: center, koans # OCP Koäns ## Open-Closed Principle - [22 Safety](http://thecodelesscode.com/case/22) - [110 The Trunk](http://thecodelesscode.com/case/110) - [112 Speak to me](http://thecodelesscode.com/case/112) - [177 The Tool-Shed](http://thecodelesscode.com/case/177) --- class: center, java # LSP 4 JAVA ## Liskov Substitution Principle ### Javaists "Let Φ(x) be a property provable about objects x of type T. Then Φ(y) should be true for objects y of type S where S is a subtype of T." A Rectangle is a Square, not the other way around. --- class: center, rationale # LSP Rationale ## Liskov Substitution Principle ### Rationale - don't mess up with the pointers "Be laxist in what you accept, strict in what you give." - keep the same interface - accept more data - grow --- class: center, ruby # LSP 4 RUBY ## Liskov Substitution Principle ### Rubyists - Composition over inheritance - Methods and fields look the same - Duck-typing makes many patterns easier - Introspection makes LAZINESS easier! --- class: center,koans # LSP Koäns ## Liskov Substitution Principle ### Koäns - [83 Consequences](http://thecodelesscode.com/case/83) - []() - []() - []() --- # ISP 4 JAVA ## Interface Separation Principle "many client-specific interfaces are better than one general-purpose interface." --- # ISP Rationale ## Interface Separation Principle - "Duplication is far cheaper than the wrong abstraction" - Reasons for change --- # ISP 4 RUBY ## Interface Separation Principle - Clever code is too clever --- # ISP Koäns ## Interface Separation Principle - [213 The Imperfect Mirror](http://thecodelesscode.com/case/213?) - [230 All Together Now](http://thecodelesscode.com/case/230) --- # DIP 4 JAVA ## Dependency Inversion Principle "one should Depend upon Abstractions. Do not depend upon concretions." --- # DIP Rationale ## Dependency Inversion Principle You can trust the idea to persist. You cannot trust the implementation. You can trust your friends, not their address. Leaky abstractions. --- # DIP 4 RUBY ## Dependency Inversion Principle I give you the info I have, you don't have to ask me. --- # DIP Koäns ## Dependency Inversion Principle - [175 Flat Shark](http://thecodelesscode.com/case/175) - [83 Consequences](http://thecodelesscode.com/case/83) - [117 Bareback](http://thecodelesscode.com/case/117) - [167 Back to Basics](http://thecodelesscode.com/case/167) --- class: left # SOLID! * `S`ingle Responsibility * `O`pen-Closed * `L`iskov Substitution * `I`nterface Separation * `D`ependency Injection --- class: left # SOLID? * don't make a mess * don't mix weird things * don't let people mess internally * who should be responsible * if it's your job, do it * if not your job, ask others * keep things in a single brain * similar things should look similar * different things should look different --- class: left # ARCHI * `A`nticipate * `R`easons for * `C`hange, be * `H`ostile to * `I`ntricacies --- class: center, middle, happy # Questions? .b[[@abelar_s](https://twitter.com/abelar_s) - [@ParisRB](https://twitter.com/parisrb) - [@RailsGirlsParis](https://twitter.com/railsgirlsparis)] [maitre-du-monde.fr](maitre-du-monde.fr) .contrib[[Contribute to this talk on GitHub!](https://github.com/abelards/abelards.github.com/edit/master/talks/SOLID.html)] --- class: center, middle, happy # Thanks! .b[[@abelar_s](https://twitter.com/abelar_s) - [@ParisRB](https://twitter.com/parisrb) - [@RailsGirlsParis](https://twitter.com/railsgirlsparis)] [maitre-du-monde.fr](maitre-du-monde.fr) .contrib[[Contribute to this talk on GitHub!](https://github.com/abelards/abelards.github.com/edit/master/talks/SOLID.html)]