Пример #1
0
        public AbstractProduct Create(string owner)
        {
            AbstractProduct product = this.CreateProduct(owner);

            this.RegisterProduct(product);
            return(product);
        }
Пример #2
0
        static void Main(string[] args)
        {
            AbstractFactory factory  = new IdCardFactory();
            AbstractProduct product  = factory.Create("test");
            AbstractProduct product2 = factory.Create("sss");

            product.Use();
            product2.Use();
        }
Пример #3
0
        static void Main(string[] args)
        {
            //Get the product instance by choosing the specific factory and user don't need to know the name of product
            IFactory        factory  = new FactoryA();
            AbstractProduct productA = factory.createInstance();

            productA.showMessage();

            factory = new FactoryB();
            AbstractProduct productB = factory.createInstance();

            productB.showMessage();

            Console.Read();
        }
Пример #4
0
        static void Main(string[] args)
        {
            Creater[] creaters = new Creater[2];

            creaters[0] = new CreaterA();
            creaters[1] = new CreaterB();

            foreach (var provider in creaters)
            {
                AbstractProduct product = provider.CreateProduct();
                Console.WriteLine("Product is: " + product.GetType().Name);
            }

            Console.ReadLine();
        }
Пример #5
0
        // простое объяснение
        static void Main3(string[] args)
        {
            // Массив фабрик
            Creator[] creators = new Creator[2];
            creators[0] = new ConcreteCreatorA();
            creators[1] = new ConcreteCreatorN();

            // Каждая фабрика создаёт свой продукт
            foreach (Creator creator in creators)
            {
                AbstractProduct product = creator.FactoryMethod();
                Console.WriteLine("Создал {0}", product.GetType().Name);
            }

            Console.ReadKey();
        }
Пример #6
0
 protected override void RegisterProduct(AbstractProduct product)
 {
     this.Owners.Add(((IdCard)product).Owner);
 }
Пример #7
0
 protected abstract void RegisterProduct(AbstractProduct product);