Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is having an empty base class bad design?

I need a base class for my DTO classes which will be used in my generic interfaces.

But the DTO classes have nothing in common. They are just dumb classes containing some properties.

public void GetGridData()
{

   IDataForGrid<DTOBase> aa;

   if(request == 1) aa = new CustomerGridData;
   if(request == 2) aa = new OrderGridData;

   var coll = aa.GetList();
}

public class CustomerGridData : IDataForGrid<CustomerDTO>
{
  ...
}
like image 423
user137348 Avatar asked Mar 11 '10 10:03

user137348


1 Answers

It is not a bad design, although somewhat uncommon. Think of it this way - there are at least two benefits while there are no drawbacks:

  • The base class serves as a filter for your interfaces so that you can't pass just any object to them - just your DTO objects. Marker interfaces could to this too.
  • When they eventually do get something in common, it will be easy to add it there and you won't have to refactor everything.
like image 131
Vilx- Avatar answered Sep 22 '22 23:09

Vilx-