• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Adapter vs. Extending Data

 
Mario Zott
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello to all of you,
while implementing the criteriaFind method, i had some thoughts about:
maybe it's better to implement the criteriaFound in a seperate class, because in my oppinion it doesn't absolutly needs to be in the Data Class - it is more an extension ... so first thing comes in mind is simply subclass Data for example in a class called DataExtended, but it's also possibly to adapt Data with a DataAdapter - which wraps all other methods and adds the methods public criteriaFind and private parseCriteria ...
especially for this assignment this class could then implement the DataClient interface instead of Data...
what do you think about it...
PS: also read something about this in Joshua Bloch's book - he thinks Adaption is better than subclassing.
 
BJ Grau
Ranch Hand
Posts: 234
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Mario Zott:
PS: also read something about this in Joshua Bloch's book - he thinks Adaption is better than subclassing.

I haven't read Josh's book, so I may be way off here but are you sure he compares adapting with subclassing? I think composition and subclassing are often compared, but the adapter pattern has a different goal than extending or composing. Adapter and composition are closely related in the fact that you create a composition in the process of forming the adapter.
Just my two cents.
 
Mario Zott
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
exactly what i meant - didn't want to confuse anyone.... but what do you think is better??
 
Max Habibi
town drunk
( and author)
Sheriff
Posts: 4118
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Mario,
This is really a context sensitive question: neither is ever 'better': it's all a matter of context.
Regarding the Data class. It seems to me that you have two options, since the documentation I had implied that you only had two choices, extending the class, or modifying it.
1. Modify Data. This has the advantage of reducing the number of necessary classes, thus reducing the complexity of the code base. OTOH, it takes away generic nature of the class.
2. extend the class. Allows specialization, but at the cost of introducing a potentially superfluous class, which is not actually used for anything.

M, author
The Sun Certified Java Developer Exam with J2SE 1.4
[ March 08, 2003: Message edited by: Max Habibi ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic