是有一个空的基类,糟糕的设计? [英] Is having an empty base class bad design?

查看:133
本文介绍了是有一个空的基类,糟糕的设计?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要一个基类为我的DTO类,它们将在我的泛型接口可以使用。

但DTO类没有任何共同之处。他们只是包含一些属性愚蠢的类。

 公共无效GetGridData()
{

   IDataForGrid< D​​TOBase> AA;

   如果(要求== 1)AA =新CustomerGridData;
   如果(要求== 2)AA =新OrderGridData;

   VAR科尔= aa.GetList();
}

公共类CustomerGridData:IDataForGrid< CustomerDTO>
{
  ...
}
 

解决方案

如果他们的没有的共同之处,你会怎样做你从你的列表中检索实例?

在任何情况下,其基类是指当(好吧,如果的),你确定这是他们的执行的必须共同以后,你不要回去和重构(重新基地)的一切。不过,我会考虑使用一个接口,而不是一个基类,这样的事情在任何情况下,因为它听起来并不像有一个强烈的需要重用的底层实现(因为他们没有任何共同之处呢!)。这将取决于你认为他们可能最终不得不在共同以后。

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>
{
  ...
}

解决方案

If they have nothing in common, what are you going to do with the instances you retrieve from your list?

In any case, having the base class means that when (okay, if) you identify something they do need to have in common later on, you don't have to go back and refactor (re-base) everything. But I'd consider using an interface rather than a base class for this sort of thing in any case, as it doesn't sound like there's a strong need to reuse underlying implementation (as they have nothing in common yet!). It'll depend on what you think they may end up having in common later on.

这篇关于是有一个空的基类,糟糕的设计?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆