+16  A: 

SRP does not apply to UIs. Keep in mind that even though the button is called "Save and Close" there can undoubtedly be two separate methods or types to handle the saving and closing functionality. The button simply ties those two separate pieces of functionality together.

If you feel the need to violate SRP then you need to re-evaluate your approach. Any SRP violation can be refactored into a new method or type that exposes the composite functionality by means of composition of the two pieces.

Andrew Hare
Actually, it applies to the UI, also. But this example shows a UI thing that is implemented by some Control and/or Model things under the hood. The question conflates UI changes with Model/Control changes; which doesn't make much sense -- each was built following SRP.
S.Lott
Yes, I agree with you. After re-reading my first sentence I realized that I am, in fact, incorrect. I think I will leave it there as your comment won't make much sense if I remove it. I appreciate your incisive comment and I don't want it to appear out of context. :)
Andrew Hare
@Andrew: By your comment, you mean, SRP should never(yeah bad choice of word) be violated and if it were to be violated, code structure need to change instead?
Sung Meister
I think "never" is just the right word. Often times the usage of "never" is very hyperbolic but in this case it isn't. *Any* violation of SRP can be refactored to remove the violation with minimal effort. I guess what I am trying to say is "Yes". :)
Andrew Hare
@Marked as Answer: Thanks Andrew. your explanation was clear in both answer and comments.
Sung Meister
+1: SRP is **never** violated -- that's precisely why a GUI is split into Model, View and Control.
S.Lott
Sung Meister

related questions