首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > C# >

血枯病模式与领域驱动模式 区别 这样对么

2014-01-15 
贫血模式与领域驱动模式 区别 这样对么?关于贫血模式与领域驱动模式贫血模式:以下为购物车DEMO(加入一个订

贫血模式与领域驱动模式 区别 这样对么?
关于贫血模式与领域驱动模式


贫血模式:以下为购物车DEMO(加入一个订单和订购商品使用同一张表)

[model.cs]
public class user
{
     public int userid { get; set; }
     public string name { get; set; }
}
public class bill//订单
{
     public int billid { get; set; }
     public int goodsid { get; set;}
     public int userid { get; set; }
}
public class goods
{
     public int goodsid{ get; set; }
     public string goodsname{ get; set; }
}

[dao.cs]
public class billdao
{
    public bool InsertBill(bill obj)
    {
          //数据验证
          //insert....略
    }

    public bool DeleteBill(bill obj)
    {
          //数据验证
          //delete....略
    }

    ....略
}

[service.cs]//服务网层
public class billservice
{
     public bool InsertBill(bill obj)
    {
        return billdao.InsertBill(obj);
    }

     public bool DeleteBill(bill obj)
    {
        return billdao.DeleteBill(obj);
    }

    ....略
}



=========================================================================================================

领域模式:

[model.cs]
public class user
{
     public int userid { get; set; }
     public string name { get; set; }
}
public class bill//订单
{
     public int billid { get; set; }
     public int goodsid { get; set;}
     public int userid { get; set; }

     public bool InsertBill(bill obj)
    {
        //数据验证
        return billdao.InsertBill(obj);
    }

     public bool DeleteBill(bill obj)
    {
        //数据验证
        return billdao.InsertBill(obj);
    }
}
public class goods
{
     public int goodsid{ get; set; }
     public string goodsname{ get; set; }
}

[dao.cs]
public class billdao
{
    public bool InsertBill(bill obj)
    {
          //insert....略
    }

    public bool DeleteBill(bill obj)
    {
          //delete....略
    }

    ....略
}

[service.cs]//服务层
public class billservice
{
    
    public bool InsertBill(bill obj)
    {
        return bill.InsertBill(obj);
    }

     public bool DeleteBill(bill obj)
    {
        return bill.DeleteBill(obj);
    }
    ....略
}



========================================================================

以上这样的区分两种模式对么 如果不对 请帮忙调整一下 我理解上有些误区 感谢指点
------解决方案--------------------


每次看到这个狗血的名字就及其不悦。血枯病模式与领域驱动模式 区别 这样对么
不知道误导多少人

贫血→结构体
领域→封装方法的类
[解决办法]
去学学o-c的基本语法,前者是之前的写法,类库提供者也就是framwork的供应商,他们提供了更智能的写法,于是出现步步省略的写法,你姑且认为,后者是前者的简写版
[解决办法]
1.领域模型 也要能够 到达解耦,最好不要出现billdao.InsertBill(obj)这种
2.领域方法 最好是自身的方法,如改变一个属性值,添加一个子集,而不是一个新对象的添加或者删除,这不是它的范畴。方法的实现最好只是简单的改变值,但是一般 它本身不发生提交保存操作,保存操作仍然是 数据操作层。

热点排行