Abstract Factory - PowerPoint PPT Presentation

About This Presentation
Title:

Abstract Factory

Description:

Design Patterns in C# Abstract Factory www.devbg.org/patternscourse/ MCAD.NET Vereo Technologies Stefan.Kiryazov[at]gmail.com – PowerPoint PPT presentation

Number of Views:78
Avg rating:3.0/5.0
Slides: 23
Provided by: Svet45
Learn more at: https://www.devbg.org
Category:

less

Transcript and Presenter's Notes

Title: Abstract Factory


1
Abstract Factory
Design Patterns in C
www.devbg.org/patternscourse/
?????? ??????? MCAD.NET
Vereo Technologies
Stefan.Kiryazovatgmail.com
2
??????????
  • ???????? ?? ???????
  • ???????
  • ????????? ?? ???????
  • ???????? ??????????
  • ??????? ??? ????????????
  • ?? ? ?????? ???????
  • ??????????

3
???????? ?? ???????
  • ?????????? ??? ??????????? ?? ??????
  • ??????? ???????? ????????? ?? ????????? ??
    ????????? ?? ???????? ?????? ??? ?? ?? ????????
    ??????????? ???????
  • ???????? ?? ?? ???????, ????????? ??
    ???????????????? ????????? ?? ??????
  • ?????????? ?????? ????????? ?? ??????? ??
    ?????????? ?????????

4
???????
  • ??????????, ?????????? ??????? ?? ??????????
    ??????????, ???????? ????
  • ????????? ???? ? ???????????? ?????? ?? ????????
    ? ?????????? ???????
  • ?? ????? ????????? ?????? ???????? ???????, ??
    ?????????? ?? ???????????? ?????? ?? ??????

5
????????? ?? ???????
6
????????? ?? ???????
  • AbstractFactory
  • ???????? ????????? ?? ????????? ?? ??????????
    ????????
  • ConcreteFactory
  • ????????? ?????????? ?? ????????? ?? ?????????
    ????????
  • AbstractProduct
  • ???????? ????????? ?? ???? ????????

7
????????? ?? ???????
  • ConcreteProduct
  • ???????? ???????, ????? ???? ???????? ??
    ??????????? ConcreteFactory
  • Client
  • ???????? ?????????? ????????????, ???????? ??
    ????????? AbstractFactory ? AbstractProduct

8
???????? ??????????
  • public static void Main()
  • // Create and run the Africa animal world
  • ContinentFactory africa new
    AfricaFactory()
  • AnimalWorld world new AnimalWorld(africa)
  • world.RunFoodChain()
  • // Create and run the America animal world
  • ContinentFactory america new
    AmericaFactory()
  • world new AnimalWorld(america)
  • world.RunFoodChain()

9
???????? ??????????
  • class AnimalWorld // Client
  • private Herbivore herbivore
  • private Carnivore carnivore
  • public AnimalWorld(ContinentFactory factory)
  • carnivore factory.CreateCarnivore()
  • herbivore factory.CreateHerbivore()
  • public void RunFoodChain()
  • carnivore.Eat(herbivore)

10
???????? ??????????
  • abstract class ContinentFactory //
    AbstractFactory
  • public abstract Herbivore CreateHerbivore()
  • public abstract Carnivore CreateCarnivore()
  • abstract class Herbivore // AbstractProductA
  • //...
  • abstract class Carnivore // AbstractProductB
  • public abstract void Eat(Herbivore h)

11
???????? ??????????
  • // ProductA1
  • class Wildebeest Herbivore
  • // ProductB1
  • class Lion Carnivore
  • public override void Eat(Herbivore h)
  • // Lion eats wildebeest
  • Console.WriteLine( "Lion eats "
    h.GetType().Name)

12
???????? ??????????
  • // ProductA2
  • class Bizon Herbivore
  • // ProductB2
  • class Wolf Carnivore
  • public override void Eat(Herbivore h)
  • // Wolf eats bizon
  • Console.WriteLine( "Wolf eats "
    h.GetType().Name)

13
???????? ??????????
  • // ConcreteFactory1
  • class AfricaFactory ContinentFactory
  • public override Herbivore CreateHerbivore()
  • return new Wildebeest()
  • public override Carnivore CreateCarnivore()
  • return new Lion()

14
???????? ??????????
  • // ConcreteFactory2
  • class AmericaFactory ContinentFactory
  • public override Herbivore CreateHerbivore()
  • return new Bison()
  • public override Carnivore CreateCarnivore()
  • return new Wolf()

15
???????????? 1
16
??????? ??? ????????????
  • ConcreteFactory ????????? ? ?????? ?? ??
    ?????????? ? ??????? singleton
  • ??????????? ?? ????? ??????? ???? ?? ?? ?????????
    ???? Factory Method.
  • ??????? ??, ?????? ?????????? ????????? ????????
    ?? ???? ????????????

17
??????? ??? ????????????
  • ??? ????? ?? ?????????? ?? ????? ????????? ??
    ??????, ??????? ?? ??? ConcreteFactory ???? ??
    ????? ????????? ???? ?? ?? ????????? ?
    ???????????? ?? ??????? ????????

18
??????? ??? ????????????
  • ???????? ?? ???? ??????? ????????
  • ? ???????????? ????????????? ? ?????, ??? ????
    ??????? ??????? ?? ?????????? ?? AbstractFactory
    ?????
  • ???????? ? ?? ?? ?????? ???? ???????????? ??
    ??????????????? ???????? ?? ????????? ?? ????????

19
?? ? ?????? ???????
  • ?? ?? ? ????????? ???????????? ?? ???????
    AbstractFactory ?????? ?? ?? ?? ???? ?????????
  • ????????? ?? ?????? ?? ?????? ?? ????????? ??
    ????????? ? ???????????? ?? ??????????
  • ?? ????? ????? ????????? ?????? ?? ???????? ????
    ??????? ???????????????? ????????? ?? ??????

20
?? ? ?????? ???????
  • ?? ?? ? ????????? ???????????? ?? ???????
    AbstractFactory ?????? ?? ?? ?? ???? ?????????
  • ???????? ?? ?????????? ????????? ?? ????????
    ?????? ?? ????????? ?????? ?????? ? ????????????
    ?????? ?? ?????? ???? ???????????
  • ?????? ?? ?? ????????? ?????????? ?? ???????
    ????????, ???? ??????? ?? ?????????? ???? ??
    ??????? ??????????

21
?????? AbstractFactory
????????
22
?????????? ??????????
  • ???? ????, ?????? ????, ???? ???????, ????
    ????????, ??????? ?? ??????, ????????, 2005, ISBN
    954-685-352-6
  • data object factory - http//www.dofactory.com/
Write a Comment
User Comments (0)
About PowerShow.com