Imagine a manufacturer producing candy. He puts the candy in a package and sends it to his customer through the local postal service. After some days the package arrives and the customer has to decide what to do with the arbritary contents of the package without knowing what is inside. This is exactly my problem:
I have this OOP problem where a "delivery service" delivers objects from a source to a consumer - multithreaded with a delay. The objects are buffered.
However, the delivery service has no class information about the stuff being delivered so the consumer has no idea what he is getting. However, this is crucial information in order to decide what to do with the delivered items, i.e. where to store them.
I was told that stuff like dynamic_cast (C++), instanceof (Java) or "is" (C#) is in general very bad OOP but I don't know how to solve this problem another way. The first thing that came into my mind was using Generics but I think this is impossible because giving the package generic information is one thing but retaining those information when the package is processed in the central delivery system is another. Dynamic casts seem to be the best solution but I am hesitating because of what I was taught from day one.
Any thoughts?