Here is my problem statement:
- I have some objects that can be either a single object, or have a tree structure of N depth. So maybe I can have objects A,B,C,D. Say A,B,C are single level objects while D have 3 children H,I,J. Among H,I,J, H and I are single objects where J again have children and so on.
- All Objects A,B,C,D,H,I,J have a behavior execute().
- I have a different class X and all these objects have to use different methods of the SAME INSTANCE OF CLASS X.
- How do I handle this scenario in a way that:
- that one function call executes the execute() method for all the objects on the same level as well as down the hierarchy.
- I dont have to pass the INSTANCE OF X to all the objects.
- Each object does some different work in its execute() method.
I could think nothing but the composite pattern but my concern was: - I dont want to pass the INSTANCE OF X to all the objects in the execute() method parameters but the method needs SAME INSTANCE OF X .
Aucun commentaire:
Enregistrer un commentaire