Reputation: 1362
Take software for a fish merchant. To sell a certain kind of fish, the UI shows a picture of the fish. The user can click it, then a window pops up in which he can select a different fish.
In a naive implementation, the component needs
Solution 1: Pass both classes along. The problem is that our component can be inside another component. So these two classes would have to be passed along to our component, creating dependencies all over the place.
Solution 2: Callbacks. Implementation using callbacks wouldn't be very clean either because the component can be inside another component, and the event would have to propagate through the whole hierarchy. This requires changes to several classes.
Any suggestions for a really clean solution?
Upvotes: 0
Views: 69
Reputation: 932
So, that would be a kind of picturebox displaying whatever fish is selected and opening a selection pop-up when clicked.
I guess that box would be part of a bigger structure whose job is presenting the selected fish. Maybe there's a label with the fish's name, another one that presents the size.. I'd have their parent component set their values when a fish is selected. It would know FishImageLibrary and be able to retrieve the image address based on the fish.
For the pop-up I think the command pattern is pretty standard for this kind of problems. It lets you pass a standardized object to your picture box that won't have to know implementation specifics of OpenSelectionPopup, which itself knows about FishSelectionPopup and how to open it.
Upvotes: 1