We'll respond shortly.
All of Sandi’s code is available here.
Fact: your application is going to change. How will your application handle that change?
Robert Martin says your app can behave a couple of different ways:
In the beginning, though, your app was perfect. “Dependencies are killing you!”
The Design Stamina Hypothesis says that, after a certain point, you’ll have done better if you had designed first.
“Skip design, if you want your app to fail.”
To avoid dependencies, your design should be:
SOLID principles we can ignore in ruby:
Really only a problem for statically-typed, compiled languages. Because we’re in Ruby, we don’t have this problem! Win!
“Dynamic languages obey this rule in the most extreme way possible: duck typing.”
When you design, don’t break the contract of the superclass in the subclass.
Sandi draws her examples of applicatoin change from the source code at: http://skmetz.home.mindspring.com/img28.html.
Lesson #1: Resistance is a Resource.
If testing seems hard, examine your design. Tests depend upon the design of the code. “TDD will punish you if you don’t understand design.”
During refactoring, ask yourself:
The answers should all be ‘yes’.
Sandi references her code to demonstrate when and how to mock and use dependency injection to achieve Single Responsibility, in which a class both downloads and acts upon the downloaded data.
She urges developers to do the simplest possible refactoring when extracting responsibilities from a class.
“Refactor, not because you know the abstraction, but because you want to find it.”
Sandi uses a very interesting example of building a Config class which behaves differently in different Rails environments. The first version had a lot of smell, and with a combination of hash parameters, YAML file, and metaprogamming, she demonstrates how to be open for extension, but closed for modification.
Sandi explains that paying attention to your classes’ dependencies is important. If a relatively static class is dependent on a class that changes more often, that’s a smell! Use dependency injection to avoid Dependency Inversion.
“TDD, BDD and DRY are all good, but they are not enough.”
“Design because you expect your app to succeed, and the future to come.”
Sandi recommends reading: