Domain Model

按老马的话说:
An object model of the domain that incorporates both behavior and data.
按我的话说:
是系统中数据和行为的一种组合方式,当然是包装到类中。这个类可以命名为我们做的项目中的名词。如:项目,包,供应商等。当然我的理解是不对的,我缺少了对业务之间关系的一种联系。
最惨的情况是业务逻辑相当的复杂。商业规则和逻辑描述了不同的场景和不同侧面的行为,这些复杂度业务对象可以解决吗。一个业务对象创建了许多连成网状的对象,这些对象表现出一些有意义的个体,或者在到一个团休,或者小到一行代码。(哈哈,英文太烂!)
At its worst business logic can be very complex. Rules and logic describe many different cases and slants of behavior, and it's this complexity that objects were designed to work with. A Domain Model creates a web of interconnected objects, where each object represents some meaningful individual, whether as large as a corporation or as small as a single line on an order form.
代码:
ContractedBlock.gif ExpandedBlockStart.gif 接口定义
 1None.gifusing System;
 2None.gif
 3None.gifnamespace DomainModel
 4ExpandedBlockStart.gifContractedBlock.gifdot.gif{
 5ExpandedSubBlockStart.gifContractedSubBlock.gif    /**//// <summary>
 6InBlock.gif    /// ISaveProduce 的摘要说明。
 7ExpandedSubBlockEnd.gif    /// </summary>

 8InBlock.gif    public interface ISaveProduce
 9ExpandedSubBlockStart.gifContractedSubBlock.gif    dot.gif{
10InBlock.gif        void Save();
11ExpandedSubBlockEnd.gif    }

12ExpandedBlockEnd.gif}
ContractedBlock.gif ExpandedBlockStart.gif 策略一
 1None.gifusing System;
 2None.gif
 3None.gifnamespace DomainModel
 4ExpandedBlockStart.gifContractedBlock.gifdot.gif{
 5ExpandedSubBlockStart.gifContractedSubBlock.gif    /**//// <summary>
 6InBlock.gif    /// SavaOne 的摘要说明。
 7ExpandedSubBlockEnd.gif    /// </summary>

 8InBlock.gif    public class SaveOne:ISaveProduce
 9ExpandedSubBlockStart.gifContractedSubBlock.gif    dot.gif{
10InBlock.gif        public SaveOne()
11ExpandedSubBlockStart.gifContractedSubBlock.gif        dot.gif{
12InBlock.gif            //
13InBlock.gif            // TODO: 在此处添加构造函数逻辑
14InBlock.gif            //
15ExpandedSubBlockEnd.gif        }

16ContractedSubBlock.gifExpandedSubBlockStart.gif        ISaveProduce 成员#region ISaveProduce 成员
17InBlock.gif
18InBlock.gif        public void Save()
19ExpandedSubBlockStart.gifContractedSubBlock.gif        dot.gif{
20InBlock.gif            //do something usefull
21ExpandedSubBlockEnd.gif        }

22InBlock.gif
23ExpandedSubBlockEnd.gif        #endregion

24ExpandedSubBlockEnd.gif    }

25ExpandedBlockEnd.gif}
ContractedBlock.gif ExpandedBlockStart.gif 策略二
 1None.gifusing System;
 2None.gif
 3None.gifnamespace DomainModel
 4ExpandedBlockStart.gifContractedBlock.gifdot.gif{
 5ExpandedSubBlockStart.gifContractedSubBlock.gif    /**//// <summary>
 6InBlock.gif    /// SaveTwo 的摘要说明。
 7ExpandedSubBlockEnd.gif    /// </summary>
 8InBlock.gif    public class SaveTwo:ISaveProduce
 9ExpandedSubBlockStart.gifContractedSubBlock.gif    dot.gif{
10InBlock.gif        public SaveTwo()
11ExpandedSubBlockStart.gifContractedSubBlock.gif        dot.gif{
12InBlock.gif            //
13InBlock.gif            // TODO: 在此处添加构造函数逻辑
14InBlock.gif            //
15ExpandedSubBlockEnd.gif        }
16ContractedSubBlock.gifExpandedSubBlockStart.gif        ISaveProduce 成员#region ISaveProduce 成员
17InBlock.gif
18InBlock.gif        public void Save()
19ExpandedSubBlockStart.gifContractedSubBlock.gif        dot.gif{
20InBlock.gif            //do something usefull
21ExpandedSubBlockEnd.gif        }
22InBlock.gif
23ExpandedSubBlockEnd.gif        #endregion
24ExpandedSubBlockEnd.gif    }
25ExpandedBlockEnd.gif}
ContractedBlock.gif ExpandedBlockStart.gif 供应商
 1None.gifusing System;
 2None.gif
 3None.gifnamespace DomainModel
 4ExpandedBlockStart.gifContractedBlock.gifdot.gif{
 5ExpandedSubBlockStart.gifContractedSubBlock.gif    /**//// <summary>
 6InBlock.gif    /// Class1 的摘要说明。
 7ExpandedSubBlockEnd.gif    /// </summary>

 8InBlock.gif    public class Produce
 9ExpandedSubBlockStart.gifContractedSubBlock.gif    dot.gif{
10InBlock.gif        private ISaveProduce _Save = null;
11InBlock.gif        public Produce()
12ExpandedSubBlockStart.gifContractedSubBlock.gif        dot.gif{
13ExpandedSubBlockEnd.gif        }

14InBlock.gif        public Produce(ISaveProduce save)
15ExpandedSubBlockStart.gifContractedSubBlock.gif        dot.gif{
16InBlock.gif            _Save = save;
17ExpandedSubBlockEnd.gif        }

18InBlock.gif        public void Save()
19ExpandedSubBlockStart.gifContractedSubBlock.gif        dot.gif{
20InBlock.gif            _Save.Save();
21ExpandedSubBlockEnd.gif        }

22ExpandedSubBlockEnd.gif    }

23ExpandedBlockEnd.gif}
ContractedBlock.gif ExpandedBlockStart.gif 客户代码
1None.gif        private void button11_Click(object sender, System.EventArgs e)
2ExpandedBlockStart.gifContractedBlock.gif        dot.gif{
3InBlock.gif            DomainModel.SaveOne one = new DomainModel.SaveOne();
4InBlock.gif            DomainModel.Produce produce = new DomainModel.Produce(one);
5InBlock.gif            produce.Save();
6ExpandedBlockEnd.gif        }


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值