开发者

SOLID SRP and FluentNhibernate entities

开发者 https://www.devze.com 2022-12-17 15:24 出处:网络
this class is from http://wiki.fluentnhibernate.org/Getting_started it has some logic in it and I think this violates the Single Responsibility Principle, how do you think, how would you resolve this

this class is from http://wiki.fluentnhibernate.org/Getting_started it has some logic in it and I think this violates the Single Responsibility Principle, how do you think, how would you resolve this ?

Another thing that bothers me is why in nhibernate always it is being used IList and not IEnumerable which has less functionality ?

public class Store
{
  public virtual int Id { get; private set; }
  public virtual string Name { get; set; }
  public virtual IList开发者_C百科<Product> Products { get; set; }
  public virtual IList<Employee> Staff { get; set; }

  public Store()
  {
    Products = new List<Product>();
    Staff = new List<Employee>();
  }

  public virtual void AddProduct(Product product)
  {
    product.StoresStockedIn.Add(this);
    Products.Add(product);
  }

  public virtual void AddEmployee(Employee employee)
  {
    employee.Store = this;
    Staff.Add(employee);
  }
}


In my opinion this does not violate the SRP principle. And, as Paco mentioned, it is still a POCO class. POCO does not mean that the object should only contain data.

I would, as you mention, however change from IList<> to IEnumerable<> on my collections and make the setters private (for the collections). That is not a problem for nhibernate to handle. Using those "add" methods is in my opinion the preferred way of handling the collections on your model (blog post about that).

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号