Active Records vs. Repository - pros and cons?

前端 未结 3 2108
孤独总比滥情好
孤独总比滥情好 2020-12-30 06:14

Using ActiveRecord you might define a class like this:

class Contact
{
  private String _name;
  public String Name
  {
    get { return _name; }
    set 
           


        
3条回答
  •  礼貌的吻别
    2020-12-30 06:35

    It really depends on how complex your domain logic is. For example if I was writing a simple blog then active record will be fine, mostly the application is saving and loading data. Its simple and active record pattern is the right tool for the job.

    However if I was writing software for a shipping company in which there are many complex business rules and processes then using the repository pattern, along with other Domain Driven Design patterns will provide at much more maintainable code in the long run.

    Using domain driven design you would use the specification pattern to achieve your validation.

提交回复
热议问题