Chapter 2 Flashcards
TRUE
Code that is Transparent, Reasonable, Usable, and Exemplary.
Determine what a class should do?
If the simplest description you can devise uses the word “and,” the class likely has more than one responsibility. If it uses the word “or,” then the class has more than one responsibility and they aren’t even very related.
Cohesion?
When everything in a class is related to its central purpose, the class is said to be highly cohesive or to have a single responsibility.
Cohesion?
When everything in a class is related to its central purpose, the class is said to be highly cohesive or to have a single responsibility.
Struct?
In Ruby it’s easy to separate structure from meaning. Just as you can use a method to wrap an instance variable, you can use the Ruby Struct class to wrap a structure.
Wheel = Struct.new(:rim, :tire)
Struct?
A convenient way to bundle a number of attributes together, using accessor methods, without having to write an explicit class.
Wheel = Struct.new(:rim, :tire)
Summary
The path to changeable and maintainable object-oriented software begins with classes that have a single responsibility. Classes that do one thing isolate that thing from the rest of your application. This isolation allows change without consequence and reuse without duplication.