工厂+单例模式

1.IBLL

namespace IBll
{
    public interface IPersonBll
    {
        int Add(string name,string type);
    }
}

 

2.BLL 继承IBLL 并且实现

namespace BLL
{
    public class PersonBll : IPersonBll
    {
        private static readonly PersonBll instance = new PersonBll();
        private PersonBll()
        { }
        public static PersonBll GetInstance()
        {
            return instance;
        }


        public int Add(string name, string type)
        {
            return 1;
        }
    }
}

3.Factory 创建需要用的接口

namespace Factory
{
    public class Facotry
    {
        private static readonly Facotry instance = new Facotry();

        private Facotry()
        {

        }

        public static Facotry getInstance()
        {
            return instance;
        }

        public IPersonBll Create_IpersonBll()
        {
            return PersonBll.GetInstance();
        }
    }
}

4.调用

 IBll.IPersonBll personBll = Factory.Facotry.getInstance().Create_IpersonBll();

 

posted @ 2016-07-27 18:23  彪悍的代码不需要注释  阅读(481)  评论(0编辑  收藏  举报
39
0