1

I'm playing around with a user interface that will allow the creation of one or multiple items of a base type that the user can manipulate.

Some of the manipulations the user makes to one object will affect the others. Think about a vector drawing tool that allows multi-select. If the user drags one object the others should move as well.

I do have a parent container object which could be responsible for handling communication between the objects but since that's all it would be doing I feel like this approach is too tightly coupled. I feel like an approach that allows the objects to communicate with each other independently of any outside classes would be a better design.

I was considering something along the lines of a singleton communicator class defined inside the object. It's purpose would be to keep a list of the objects and alert the other objects to various events such as a new object being added, removed or some other manipulation that may or may not affect the behavior of the other objects.

Is this a bad design? Off the cuff thoughts are appreciated as well as any resources you may have on the subject. Thanks!

4

1 回答 1

1

I think I would go with a Composite instead.

In the multiple select case, add all selected objects to the Composite instance. You can now manipulate the group as a whole via the Composite.

于 2012-10-09T07:00:56.837 回答