• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Is this a design pattern?

 
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
author
Posts: 608
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for the comment, Scott!

Regards,
Varun
 
(instanceof Sidekick)
Posts: 8791
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 1170
Hibernate Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It does contain elements of the Decorator pattern.
 
Ranch Hand
Posts: 862
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ]
 
author
Posts: 14112
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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...
 
author and iconoclast
Posts: 24207
46
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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."
 
Ranch Hand
Posts: 385
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Posts: 14112
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
reply
    Bookmark Topic Watch Topic
  • New Topic