Suppose I have a controller class with a bunch of properties. Each time a property is changed, I would like to update the model. Now also suppose that I use the command pattern to perform model updates. Is it common to use command classes within property get and sets of the controller class or is there a better way?

Here is an example of what I am currently using:

class MyController {
  private int _myInt;
  public int MyInt {
    get { return _myInt; }
    set {
      MyCommand cmd = new MyCommand();
      cmd.Argument = _myInt;
      cmd.Execute();  // Command object updates the model
  • How does that work when you have multiple instances of MyController? Wouldn't the value of _myInt get out of sync? Commented Jan 6, 2011 at 4:53
  • Dean, no because _myInt is not static
    – user2567
    Commented Jan 6, 2011 at 8:09

2 Answers 2


I would think it's more common to have property value changes raise an event. Then, the model or whatever object is in charge of updating the model can subscribe to it and perform the updates that way.


Usually one tries to keep property setters "stupid", that is, perform basic field updates of its own class and avoid doing too much extra work which can potentially fail (throw an exception).

If you need extra work to be done, better make the setter to a method.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.