Domain Model

it2022-05-09  22

按老马的话说: 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. 代码: 接口定义  1using System; 2 3namespace DomainModel 4{ 5    /**//// <summary> 6    /// ISaveProduce 的摘要说明。 7    /// </summary> 8    public interface ISaveProduce 9    {10        void Save();11    }12} 策略一  1using System; 2 3namespace DomainModel 4{ 5    /**//// <summary> 6    /// SavaOne 的摘要说明。 7    /// </summary> 8    public class SaveOne:ISaveProduce 9    {10        public SaveOne()11        {12            //13            // TODO: 在此处添加构造函数逻辑14            //15        }16        ISaveProduce 成员#region ISaveProduce 成员1718        public void Save()19        {20            //do something usefull21        }2223        #endregion24    }25} 策略二  1using System; 2 3namespace DomainModel 4{ 5    /**//// <summary> 6    /// SaveTwo 的摘要说明。 7    /// </summary> 8    public class SaveTwo:ISaveProduce 9    {10        public SaveTwo()11        {12            //13            // TODO: 在此处添加构造函数逻辑14            //15        }16        ISaveProduce 成员#region ISaveProduce 成员1718        public void Save()19        {20            //do something usefull21        }2223        #endregion24    }25} 供应商  1using System; 2 3namespace DomainModel 4{ 5    /**//// <summary> 6    /// Class1 的摘要说明。 7    /// </summary> 8    public class Produce 9    {10        private ISaveProduce _Save = null;11        public Produce()12        {13        }14        public Produce(ISaveProduce save)15        {16            _Save = save;17        }18        public void Save()19        {20            _Save.Save();21        }22    }23} 客户代码 1        private void button11_Click(object sender, System.EventArgs e)2        {3            DomainModel.SaveOne one = new DomainModel.SaveOne();4            DomainModel.Produce produce = new DomainModel.Produce(one);5            produce.Save();6        }

转载于:https://www.cnblogs.com/nanshouyong326/archive/2006/11/30/578029.html


最新回复(0)