Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Is this a design pattern?

 
Varun Dikshit
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

Is this an already establised design pattern?

1) An interface, say I
2) A class, say A, that implements the interface I
3) Another class, say B, that implements I and extends A
4) Another class, say C, that implements I and extends A

Now, A has a couple of abstract methods for separate functional implementations in B and C. B and C also share some of the common methods of A. These commmon methods in A can call the abstract methods which will be called dynamically based on whether B or C, as a concrete implementation of I, is in operation.

This seems to me an efficient way to delegate reponsibilities at runtime.

Comments?
 
Scott Ambler
author
Ranch Hand
Posts: 608
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Patterns are solutions to common problems, and this isn't what you've described. Instead, you've captured a common design strategy for generalization structures. It's a good strategy, but it's not a pattern.

- Scott
 
Varun Dikshit
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the comment, Scott!

Regards,
Varun
 
Stan James
(instanceof Sidekick)
Ranch Hand
Posts: 8791
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That's one characteristic design in "frameworks" where an abstract A controls the flow through a common task and calls abstract methods that B and C must override to do their custom bits of the task.
 
Mr. C Lamont Gilbert
Ranch Hand
Posts: 1170
Eclipse IDE Hibernate Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It does contain elements of the Decorator pattern.
 
steve souza
Ranch Hand
Posts: 862
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Not sure I understand your posting, but it sounds like the "Template Method" design pattern.

http://www.dofactory.com/Patterns/PatternTemplate.aspx
http://home.earthlink.net/~huston2/dp/templateMethod.html
[ August 31, 2005: Message edited by: steve souza ]
 
Ilja Preuss
author
Sheriff
Posts: 14112
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by steve souza:
Not sure I understand your posting, but it sounds like the "Template Method" design pattern.


Yes, that was my thought, too...
 
Ernest Friedman-Hill
author and iconoclast
Marshal
Pie
Posts: 24211
35
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hate to be the third "me too", but I guess I can help balance out the dissenting posts that started the replies. Yes, this is precisely the "template method pattern."
 
Vladas Razas
Ranch Hand
Posts: 385
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can we say "Abstract Class" instead of "Template Method Pattern" ?
 
Vladas Razas
Ranch Hand
Posts: 385
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
One more comment: if B,C extends A then they do automatically ands always implement I.
 
steve souza
Ranch Hand
Posts: 862
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What you described in your original post is more than an abstract class. The way your various classes interact in their inheritance structure makes it the 'template method'. One of the biggest benefits of using design patterns is that they enable you to communicate a whole design with one phrase. By calling it an abstract class you would be forced to explain in words your design. That is not true if you use the proper name: Template method
[ September 02, 2005: Message edited by: steve souza ]
 
Ilja Preuss
author
Sheriff
Posts: 14112
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Vladas Razas:
Can we say "Abstract Class" instead of "Template Method Pattern" ?


No. Template Method is a pattern that makes use of an abstract class to define a high level algorithm, and delegate implementation of low level details to subclasses by calling abstract methods.

With other words, not every use of an abstract class is an implementation of the Template Method pattern.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic