Say I have a method that handles incoming data objects. It must handle each data type differently. Given the choice of two method signatures:
void sendObjects(ObjectType enum, Collection<SendableObject> objects) where enum denotes the type of objects in the collection and each object has a ObjectType getType() method,
and
void sendObjects(Collection<SendableObject> objects) where getClass() is used to determine the type.
Which approach is better and why? We recently had a discussion about this at my company, and I’m curious to hear what the community thinks.
The enum doesn’t add anything. In fact it risks being wrong, since the caller can mix it up. I’d go with checking the class or the
ObjectType getType()on every object, but not send in the enum as argument.