Is is common to use the command pattern for property get/sets?

Posted by k rey on Programmers See other posts from Programmers or by k rey
Published on 2011-01-06T04:30:19Z Indexed on 2011/01/06 4:59 UTC
Read the original article Hit count: 321

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
    }
  } 
}

© Programmers or respective owner

Related posts about best-practices

Related posts about c#