Thanks for your time!
I recently read about template pattern(in Ruby) and want to use this pattern in my codes.
My question is "where to put some commonly used functions".
Say I have TemplateRequestBody, JSONRequestBody and XMLRequestBody as following.
raised "called abstract method: pretty_format"
class JSONRequestBody < TemplateRequestBody
# pretty format JSON
class XMLRequestBody < TemplateRequestBody
# pretty format XML
As it always is - it depends :)
If a method will be shared across subclasses, putting it in the parent class (
TemplateRequestBody) would make sense. If the methods will not be shared across the subclasses, then don't put them.
If method is going to be used by some of the classes, maybe you could think if a mixin would be a good place to store that method? Also, putting it in the parent class won't be a terrible idea.
Hope that helps!