设计模式--抽象工厂,与生活结合

来源:互联网 发布:淘宝客挣钱吗 编辑:程序博客网 时间:2024/06/06 08:49

一、我的理解

             1、一系列的产品创建提供支持

             2、减轻创建对象所需要知道的细节            


二、现实运用

            1、女娲造人

            2、导航网站,访问导航网站就能任意去想要去的网站,而无需知道具体网站地址


三、代码

using System;using System.Collections.Generic;using System.Text;namespace ModeDemo.AbstractFactory{    public abstract class AbstractFactoy    {        public abstract AbstractProductA CreateProductA();        public abstract AbstractProductB CreateProductB();    }}

using System;using System.Collections.Generic;using System.Text;namespace ModeDemo.AbstractFactory{    public abstract class AbstractProductA    {    }}

using System;using System.Collections.Generic;using System.Text;namespace ModeDemo.AbstractFactory{    public abstract class AbstractProductB    {        public abstract void Interact(AbstractProductA a);    }}

using System;using System.Collections.Generic;using System.Text;namespace ModeDemo.AbstractFactory{    public abstract class AbstractProductB    {        public abstract void Interact(AbstractProductA a);    }}

using System;using System.Collections.Generic;using System.Text;namespace ModeDemo.AbstractFactory{    public class ConcreateFactory2:AbstractFactoy    {        public override AbstractProductA CreateProductA()        {            return new ProductA2();        }        public override AbstractProductB CreateProductB()        {            return new ProductB2();        }    }}


原创粉丝点击