title: Implementing a CRUD using an Interface
body: <p>What is the best approach to implement a CRUD on the BL using interface that will be used to abstract DAL operations? I need your opinion guys..</p>
  
  <p>Here's my draft..</p>
  
  <p>Data Entities that are mapped in the database table</p>
  
  <pre><code> public class Student
   {
      public string StudentId { get; set; }
      public string StudentName { get; set; }
      public Course StudentCourse { get; set; }
   }
  
   public class Course
   {
      public string CourseCode { get; set; }
      public string CourseDesc { get; set; }
   }
  </code></pre>
  
  <p>I created an CRUD Interface to abstract the object's operations</p>
  
  <pre><code>public interface IMaintanable&lt;T&gt;
  {
     void Create(T obj);
     T Retrieve(string key);
     void Update(string key);
     void Delete(string key);
   }
  </code></pre>
  
  <p>And then a component that manages the Entity and its operations by implementing the interface</p>
  
  <pre><code>public class StudentManager : IMaintainable&lt;Student&gt;
  {
      public void Create(Student obj)
      {
          // inserts record in the DB via DAL
      }
  
      public Student Retrieve(string userId)
      {
          // retrieveds record from the DB via DAL
      }
  
      public void Update()
      {
          // should update the record in the DB
      }
  
      public void Delete(string userId)
      {
          // deletes record from the DB
      }
  }
  </code></pre>
  
  <p>sample usage</p>
  
  <pre><code>    public void Button_SaveStudent(Event args, object sender)
      {
          Student student = new Student()
          {
             StudentId = "1", StudentName = "Cnillincy"
          }
  
          new StudentManager().Create(student);   
       }
  </code></pre>
  
  <p>as you can see, there is quite an abnormalities on the update method</p>
  
  <pre><code>    public void Update()
      {
          // should update the record in the DB
      }
  </code></pre>
  
  <p>what should this method have to update the objects property? should I inherit the <strong>Student</strong>?</p>
  
  <pre><code>    public class StudentManager : Student , IMaintainable&lt;Student&gt;
      {
          public void Update()
          {
              //update record via DAL
           }
      }
  
  
      public void Button_SaveStudent(Event args, object sender)
      {
          Student student = new StudentManager();
          student.StudentId = "1";
          student.StudentName = "Cnillincy"
          student.Update()
      }
  </code></pre>
  
  <p>Or should I just contain the Student class as an attribute of the Student manager?</p>
  
  <pre><code>     public class StudentManager : IMaintainable&lt;Student&gt;
      {
          public Student student { get; private set };
  
          public void Create() {}
          public void Update() {}
          public void Retrieve() {}
          public void Delete() {}
      }
  </code></pre>
  
  <p>Which more appropriate? What about the interface? Any other suggestions guys? thanks..C</p>