L
Lucas White
Hi,
Is it considered good practice to wrap the Collection implementation
classes? For example, if I have a list of animals, should I just
have:
List animals = new ArrayList();
animals.add(new Animal("Cat"));
....
Or should I have an AnimalCollection class which encapsulates the
list's workings. That way I could make sure every object added to my
animal list was an Animal object, whereas any object could be added to
a List that isn't wrapped.
Any ideas on the positives and negatives of both approaches? If I'm
not being clear, let me know and I'll explain further.
Thanks,
Lucas
Is it considered good practice to wrap the Collection implementation
classes? For example, if I have a list of animals, should I just
have:
List animals = new ArrayList();
animals.add(new Animal("Cat"));
....
Or should I have an AnimalCollection class which encapsulates the
list's workings. That way I could make sure every object added to my
animal list was an Animal object, whereas any object could be added to
a List that isn't wrapped.
Any ideas on the positives and negatives of both approaches? If I'm
not being clear, let me know and I'll explain further.
Thanks,
Lucas