views:

20

answers:

1

Hallo,

Why do I need 2 classes to get my data? Why is a DataProvider class not enough, if the Service does actually nothing except call the method in the DataProvider ?

interface ICustomerDataProvider
inferface ICustomerService

class CustomerDataProvider : ICustomerDataProvider
{
    // Do Sql queries here
    // return sql data and write all DataReader data into customer objects....

   public  IEnumerable<Customer> GetCustomers()
 {
    return ...
 }

}

class CustomerService : ICustomerService
{
    public IEnumerable<Customer> GetCustomers()
  {
       return _customerDataProvider.GetCustomers();
  }    
}

class BillingViewModel
{

  _customerService = Service.Resolve<ICustomer>();

 IEnumerable<Customer> customers = _customerService.GetCustomers();

  Customers = new ObservableCollection<Customer>(customers);

}
+1  A: 

if your service layer just call methods in your data providers, it means you have some problem in your design.

Data Providers are used to pull and push data. It takes small actions.

Service Layer performs "big actions", which composites small actions.

Take saving a blog post as an example: Data Providers do these seperatly

  1. SavePost()
  2. SaveTags()

while service layer just does one

 AddPost()
 {
     SavePost();
     SaveTags();
 }
Jun1st
does not sound logically to me.One of these layers seem redundant to me.Why not call from your ViewModel/Presenter:_dataProvider.SavePost();_dataProvider.SaveTags(); ???saves one layer...You speak of composition or aggregation aka aggregated entities.What if my service does not have composited methods? Then its also overfluid.
msfanboy
Does it not depend on someones requirements to use a dataprovider WITH a service?
msfanboy
To ViewModel/Presenter, You should provider less and simple call to them.To ViewModel, It should just take care of what to save, but now how to save. If your framework is used by someone else, you make an assumption that he knows he should call "SaveTags" method when saving a post. This is not the case until you told him toWhat's more, if you want to modify your "AddPost" implementation, you can keep the change to yourself as long as you don't change the interface.
Jun1st