Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

7
  • Great suggestion. I'm gonna do this with my current example. But what about when such a design is not possible/wanted? Or do you decide on the spot what the best way is to handle it? Commented Aug 17, 2015 at 10:54
  • 5
    @Kevin: It depends really. Sometimes you can solve the issue by iterating over a collection, sometimes not, but the key principle is to avoid duplication and to make it easy to preserve invariants. The more "manual" actions need be remembered for things to work properly, the less chances you have that things will work properly. I hate to be vague here, but there are so many different situations that I am afraid a "generic" rule would just lead you astray. Commented Aug 17, 2015 at 11:02
  • 24
    "make it easy to preserve invariants" is a generic rule worth remembering. Commented Aug 17, 2015 at 14:06
  • 1
    @Tonny: I don't know if encouraging the use of a global variable is "doing it right", but indeed if you know exactly which was active before, you need only update two views. Another solution is for each view to remember its visibility and for setVisibility not to do anything if the visibility is already the one requested, which moves the responsibility down. Commented Aug 17, 2015 at 15:19
  • 1
    @MatthieuM. I wrote in haste, but is actually what I meant too. If you know the previous state you only need to update 2 view at most. How to remember that state is another matter ;-). As for moving the responsibility down: If the view-class doesn't provide for that you would need to wrap the class in another object just to add that property. That is a clean solution, but maybe a bit overkill. Commented Aug 20, 2015 at 13:59