I'd like to use the Composite pattern for forwarding calls received by one object to others.
At present, objects on the receiving end are all of the same Abstract
type but the snag is that they selectively accept different types of objet as parameters according to their concrete type (think different models).
As far as I can see, there are two solutions but neither is satisfactory:
- Use instanceof to detect the class type objects on the input side. This is often said to be a bad practise.
- Make as many
Lists
as there are input types. This brings the problem that aList
has to be added to accomodate a new input type and eachList
has to be explicitely processed in turn.
I've been thinking in terms of interfaces but have not come up with a feasible idea as of yet. What would be a solution to this design issue? Is a composite appropriate at all?
P.S: This is in the context of an mvc.