RE: Template Method Pattern (GoF) without abstract methods in Ruby

Andy Jones <[email protected]>
Newsgroups gmane.comp.lang.ruby.general
Message-ID <[email protected]>
My 10p:

Many of these patterns were designed for older languages with more basic features.  I looked up Template Method -- and, please correct me if I've got the wrong end of the stick -- this is just polymorphism, a basic feature of OOP?

I know Ruby coders often shy away from inheritance (with good reason) but personally this is probably one of those times to consider using it.

Obviously Ruby doesn't have abstract classes or abstract methods.  But AFAIK the idiomatic way to simulate an abstract method in Ruby is:

#########
def foo
  fail NotImplementedError, "You need to override this method"
end
#########

...and of course an "abstract class" is any class that has an abstract method in it.

I'm sure that there are dozens of other ways to achieve this goal, other than using inheritance. And, as I say, perhaps I've misunderstood the problem.  But for my money if it looks like polymorphism then you want inheritance.



Click here to view Company Information and Confidentiality Notice.<http://www.jameshall.co.uk/index.php/small-print/email-disclaimer>

Please note that we have updated our privacy policy in line with new data protection regulations. Please refer to our website to view the ways in which we handle your data.

Unsubscribe: <mailto:[email protected]?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-talk>
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.