genralization or composition

hi,i have a class which have to perfom somes processes on a set of object.i want to know if it's better to extend HashSet (by exple) or to use it in my classe as a private attribute.thanx in advance. badr.
[241 byte] By [zbadra] at [2007-9-28 15:04:53]
# 1
In general, if your class "is a" HashSet (for example), then it is appropriate to extend HashSet, otherwise you should wrap and delegate to it. There is a nice discussion of this topic in "Effective Java".Hope that helpsLee
tsitha at 2007-7-12 11:47:46 > top of Java-index,Other Topics,Patterns & OO Design...
# 2

Unless you need to enhance or possibly change the behavior of the HashSet it is better to have a class that contains a HashSet internally and presents an external interface similar to the HashSet. This type of a design pattern implementation is called an Adapter.

Based on my experience there has only been a couple of times where I have felt it was necessary to extend one of the Collection classes. Most of the time I go for the adapter.

jonathanhousea at 2007-7-12 11:47:46 > top of Java-index,Other Topics,Patterns & OO Design...
# 3
thank you all ;-)
zbadra at 2007-7-12 11:47:46 > top of Java-index,Other Topics,Patterns & OO Design...