Edisode 5 - Example 1 to Example 9
27 Jun 2008, 16:55
Bharat Ruparel (146 posts)
First, some feedback. This is excellent. I am posting below my ruby newbie critique for each and hope to get your feedback. Your were understandably more reserved in offering your preferences since you were the presentor.
Example 1 - Pros - Simplest way to get going. Cons - Lacks separation of concerns and responsibility. In general - Not recommended.
Example 2 - Pros - Separation of concerns. Cons - Static inheritance promotes tight coupling just as in C++ and Java. In general - Not recommended in Ruby world.
Example 3 - Pros - Dynamic creation of sub-class. Use of closures avoids having to maintain instance variables, instead, ruby carries it around for us as closures. In general - can be used in Ruby world, but there are better ways as shown in next example.
Example 4 - Pros - Ruby favored use of Singleton (or ghost - Thanks David for using this term, it cleared up a lot of confusion about Singleton in my mind) as a quick one of to customize the behavior of an existing class (DisCounter). Cons - No generalization. In general - use this approach for one of cusstomizations on the fly where reuse is not of paramount importance.
Example 5 - Pros - Singletons generalized, promotes looser coupling. Cons - None really. In general - One of the Ruby recommended approaches. Question for you David. Is the ghost class somewhat similar to a proxy class in Java world?
Example 6 - Pros (?) - Demonstrates Ruby’s flexibility in aliasing an existing method and redefining it. Cons - Tight coupling results in lack of reusability of memoization code.
Example 7 - Pros - Removes the tight coupling introduced in example 6. Cons - Weird naming of methods. Can be cleaned up. In general can be used if you don’t mind the weird naming (I don’t but I am a unix shell script programmer, is there any other reason not to use this approach?).
Example 8 - Cleaner syntax, but same thing really as Example 7.
Example 9 - This is the one that I don’t get yet, but as you are pointing out, I need to puts in various places and try to think what is happening where and why. Any pointers in trying to understand it are greatly apprecited.
Let me know if I have missed anything anywhere or am wrong in my interpretation (I won’t be surprised).
Thanks again, and you were right. This worked out much better than a number of books that I have (including yours). I will go back and review them.
|You must be logged in to comment|