【发布时间】:2017-04-12 05:03:05
【问题描述】:
我对 OOP 中的继承概念有一些疑问。当我刚刚完成自定义类的编码以连接数据库时。
例如
`// for encapsulate some method under and use as the team's custom
// version of DBconnect
public class DBconnector()
{
public void SetConnection(); // setting
public void BeginCon(); // setting
public void SetQuery(String i_Query , CommandType cmdType); // setting
public Object GetExcetue();
... // other setting
}`
然后系统具有单独的业务逻辑分类,将为其模块获取内容(来自数据库的数据),例如 BusinessLogicM1 、 BusinessLogicM2 、 BusinessLogicM3 ...
这些单独的分类将通过使用 DBconnector 的功能从 Db 获取数据。所以我在这里混淆是否应该通过从 DBconnector 类继承来编码 BusinessLogic 类,只使用 DBconnector 的方法。public class BusinessLogicX :DBconnector
{
public Object GetXData()
{
...// setting
return this.GetExcetue();
}
}
或public class BusinessLogicX
{
public Object GetXData()
{
var service = new DBconnector();
...//setting
return service.GetExcetue();
}
}
【问题讨论】:
标签: c# oop inheritance