Meaningless Drivel is fun!*
The moose likes OO, Patterns, UML and Refactoring and the fly likes Is this a design pattern? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » OO, Patterns, UML and Refactoring
Bookmark "Is this a design pattern?" Watch "Is this a design pattern?" New topic
Author

Is this a design pattern?

Varun Dikshit
Greenhorn

Joined: Feb 15, 2005
Posts: 18
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

Joined: Dec 12, 2003
Posts: 608
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


<a href="http://www-306.ibm.com/software/rational/bios/ambler.html" target="_blank" rel="nofollow">Scott W. Ambler</a><br />Practice Leader Agile Development, IBM Rational<br /> <br />Now available: <a href="http://www.ambysoft.com/books/refactoringDatabases.html" target="_blank" rel="nofollow">Refactoring Databases: Evolutionary Database Design</a>
Varun Dikshit
Greenhorn

Joined: Feb 15, 2005
Posts: 18
Thanks for the comment, Scott!

Regards,
Varun
Stan James
(instanceof Sidekick)
Ranch Hand

Joined: Jan 29, 2003
Posts: 8791
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.


A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi
Mr. C Lamont Gilbert
Ranch Hand

Joined: Oct 05, 2001
Posts: 1170

It does contain elements of the Decorator pattern.
steve souza
Ranch Hand

Joined: Jun 26, 2002
Posts: 860
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 ]

http://www.jamonapi.com/ - a fast, free open source performance tuning api.
JavaRanch Performance FAQ
Ilja Preuss
author
Sheriff

Joined: Jul 11, 2001
Posts: 14112
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...


The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - Heraclitus
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24183
    
  34

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."


[Jess in Action][AskingGoodQuestions]
Vladas Razas
Ranch Hand

Joined: Dec 02, 2003
Posts: 385
Can we say "Abstract Class" instead of "Template Method Pattern" ?
Vladas Razas
Ranch Hand

Joined: Dec 02, 2003
Posts: 385
One more comment: if B,C extends A then they do automatically ands always implement I.
steve souza
Ranch Hand

Joined: Jun 26, 2002
Posts: 860
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

Joined: Jul 11, 2001
Posts: 14112
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.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Is this a design pattern?
 
Similar Threads
iterface method
is-a relationship
event handling
Abstract inner class?
interface and abstract class