Suppose I have an Item class which is the base class of a composite pattern.
I have two specific subclasses Movie and Music containing different data :
If I want to access Movie data (for example) in a client code, I need to downcast the Item corresponding to it because getProducer() is not a method of the Item class.
I am stuck between three different approach :
The third proposition seems interesting because it hides Item subclasses to client, but I don't know how to let client update an Item (for example change the producer of a movie).
The Item subclasse types supported by the application will grow through releases, and I want to design it to facilitate those type additions.
Maybe I am totally going in the wrong way and there is a different and better solution.
Option 1 is a bad idea, simply because getProducer() does not belong to an item.
Option 3 would work if you'd also proved setters in addition to the getter methods you were planning to implement there.
Option 2 sounds the most reasonable to me. Casting is a common task in a polymorphic solutions and in your case it is adequate.