Jeeva
Jeeva

Reputation: 4663

Design for CRUD

I have a requirement for designing a CRUD application. There are three tables in DB - Employees, Sales and Customer. The values for these tables are available in three different spread sheet. My app should go and check the spreadsheet periodically and update the corresponding table. I have come up with the following design

EmpMgr - EmpDAL - EmpDAO

SalesMgr - SalesDAL - SalesDAO

CustMgr - CustDAL - CustDAO

The timer in my main app will periodically go and get the spreadsheet available in the configured location and call Parse function in either EmpMgr, SalesMgr or CustMgr . The respective classes parse the file and form "Vector of EmpDao/SalesDao/CustDao" and call the corresponding DAL to update the table.

My apprehension about this approach is

  1. The parsing of excell file may be repeated in all the Mgr classes. If i want to create a generic parser how should i make it return concrete "Vector of DAO"?
  2. Today the data is from excell may be it will get changed to XML or even web service. How should i make sure my design will accommodate the changes?

Upvotes: 0

Views: 595

Answers (1)

Sunil Khiatani
Sunil Khiatani

Reputation: 337

You are missing the model (think MVC). This should solve both your problems. I don't think you will need a DAL layer.

e.g for the excel sheet that holds a list of employees. You should have a concrete class for employees. A list of employees can be held in a List Container. Your DAO will parse excel, and turn each row into an employee object, or accept an employee object and add it as a row in excel.

For your first question, your code might look like this.

class EmployeeManager()
{
   ...

   public void CreateEmployee(Employee employee)
   {
       dao.Add(employee);
   }

   public void CreateEmployees(List<Employee> employees)
   { 
       dao.AddMany(employees);
   }

   ...

   public List<Employee> GetAllEmployees()
   {
       List<Employee> employees = dao.GetAll();
       employees.Sort();
   }

   ...
}

class Employee()
{
   Employee(string name, string job)
   {
      Name = name;
      Job = job;
   }

   ...

   string Name { get; set; }
   string Job { get; set; }
}

class EmployeeDAO()
{

   ...

   public List<Employee> GetAllEmployees() 
   {

        List<Employee> employees = new List<Employee>;

        //parse all rows and make make employee objects out of them.

        return employees;           
   }

}

For Q1, by using the model, you will be using the containers provided by C# to hold a list of employees, they can be searched, sorted, modified etc, and the code is already done for you, tried and tested for you and written by people much smarter than you.

For Q2, If you change the from Excel to XML or anything else, all you need to do is modify the DAO. Anything using the manager will only need to use the classes in your model, and make use of the Containers already in C#.

Upvotes: 1

Related Questions