locked
single responsibility principle RRS feed

  • Question

  • User888441741 posted

    i have a question regarding the SRP, let say i have IRespository in my DomainMode.Repository project

     public interface IRepository<T>
        {
            void Save(T obj);
            void Add(T obj);
            T FindBy(Guid id);
            List<T> FindAll();
        }

    i have implement the above interface in my concreate class. so my question is am i not violating rules of SRP here?

    Monday, March 22, 2010 2:07 PM

All replies

  • User1477435862 posted

    Why do you think you're violating SRP?

    What you've explained is good OOP and a very common way of using the repository pattern.

    Monday, March 22, 2010 2:25 PM
  • User888441741 posted

    Why do you think you're violating SRP?

    What you've explained is good OOP and a very common way of using the repository pattern.

     

    SRP; states that: A class or module should have one, and only one, reason to change.....

    but if i implement my interface to my concreate class, dont you think that i will have four reason to change my class?

    Undecided

    Monday, March 22, 2010 2:33 PM
  • User1477435862 posted

    I think that you're thinking too granularly about "Single" responsibility.  In this case, "Single" means data access.  Therefore, the class shouldn't consider business or presentation logic, for example.  To apply "Single" in your terms would require a separate class for every method, which is impractical.

    Tuesday, March 23, 2010 6:40 AM
  • User888441741 posted

    I realized later after i post. thanks

    but why do you think its impractical?

     

    Tuesday, March 23, 2010 9:20 AM