1 / 11

Шаблоны проектирования ООП

Шаблоны проектирования ООП. Принципы ООП. Инкапсуляция Наследование Полиморфизм Абстракция данных. Паттерны. Основные шаблоны ( Fundamental) Порождающие шаблоны проектирования ( Creational) Структурные шаблоны ( Structural) Поведенческие шаблоны ( Behavioral)

milica
Download Presentation

Шаблоны проектирования ООП

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Шаблоны проектированияООП

  2. Принципы ООП Инкапсуляция Наследование Полиморфизм Абстракция данных

  3. Паттерны Основные шаблоны (Fundamental) Порождающие шаблоны проектирования (Creational) Структурные шаблоны (Structural) Поведенческие шаблоны (Behavioral) Шаблоны параллельного программирования (Concurrency) MVC Enterprise И тд.

  4. Основные шаблоны (Fundamental) • Delegation pattern/Шаблон делегирования • Functional design/Шаблон функционального дизайна • Immutable/Неизменяемый объект • Interface • Property Container

  5. Порождающие шаблоны проектирования (Creational) • Abstract Factory • Builder • Factory Method • Lazy initialization • Multiton • Object Pool • Prototype • Resource acquisition is initialization (RAII) • Singleton

  6. Abstract Factory class Client { private AbstractProductA abstractProductA; private AbstractProductB abstractProductB; public Client(AbstractFactory factory) { abstractProductB = factory.CreateProductB(); abstractProductA = factory.CreateProductA(); } public void Run() { abstractProductB.Interact(abstractProductA); } } public static void Main() { AbstractFactory factory1 = new ConcreteFactory1(); Client c1 = new Client(factory1); c1.Run(); } abstract class AbstractFactory { public abstract AbstractProductA CreateProductA(); public abstract AbstractProductB CreateProductB(); } class ConcreteFactory1 : AbstractFactory { public override AbstractProductA CreateProductA() { return new ProductA1(); } public override AbstractProductB CreateProductB() { return new ProductB1(); } } abstract class AbstractProductB { public abstract void Interact(AbstractProductA a); }

  7. Abstract Factory

  8. Factory Method using System; class MainApp { static void Main() { Creator[] creators = new Creator[2]; creators[0] = new ConcreteCreatorA(); creators[1] = new ConcreteCreatorB(); foreach(Creator creator in creators) { Product product = creator.FactoryMethod(); Console.WriteLine("Created {0}", product.GetType().Name); } // Wait for user Console.Read(); } } abstract class Product{ } class ConcreteProductA : Product { } class ConcreteProductB : Product { } abstract class Creator { public abstract Product FactoryMethod(); } class ConcreteCreatorA : Creator { public override Product FactoryMethod() { return new ConcreteProductA(); } } class ConcreteCreatorB : Creator { public override Product FactoryMethod() { return new ConcreteProductB(); } }

  9. Factory Method

  10. Builder abstract class Builder { public abstract void BuildPartA(); public abstract void BuildPartB(); public abstract Product GetResult(); } class ConcreteBuilder1 : Builder { private readonly Product product = new Product(); public override void BuildPartA() { product.Add("PartA"); } public override void BuildPartB() { product.Add("PartB"); } public override Product GetResult() { return product; } }

  11. Builder

More Related