Abstract Factory in VB.NET
Creates an instance of several families of classes
ReturnProvide an interface for creating families of related or dependent objects without specifying their concrete classes. Object creation has been abstracted and there is no need for hard-coded class names in the client code.
Please download project with this source code from https://github.com/ViacheslavUKR/StandardDisignOopPattern
1: ' Abstract Factory Design Pattern.
2: ' See description in //www.vb-net.com/ProgramTheory/AbstractFactory.htm
3: Class MainApp
4: ' Entry point into console application.
5: Public Shared Sub Main()
6: ' Abstract factory #1
7: Dim factory1 As AbstractFactory = New ConcreteFactory1()
8: Dim client1 As New Client(factory1)
9: client1.Run()
10: ' Abstract factory #2
11: Dim factory2 As AbstractFactory = New ConcreteFactory2()
12: Dim client2 As New Client(factory2)
13: client2.Run()
14: ' Wait for user input
15: Console.ReadKey()
16: End Sub
17: End Class
18:
19: ' The 'AbstractFactory' abstract class
20: MustInherit Class AbstractFactory
21: Public MustOverride Function CreateProductA() As AbstractProductA
22: Public MustOverride Function CreateProductB() As AbstractProductB
23: End Class
24:
25: ' The 'ConcreteFactory1' class
26: Class ConcreteFactory1
27: Inherits AbstractFactory
28: Public Overrides Function CreateProductA() As AbstractProductA
29: Return New ProductA1()
30: End Function
31: Public Overrides Function CreateProductB() As AbstractProductB
32: Return New ProductB1()
33: End Function
34: End Class
35:
36: ' The 'ConcreteFactory2' class
37: Class ConcreteFactory2
38: Inherits AbstractFactory
39:
40: Public Overrides Function CreateProductA() As AbstractProductA
41: Return New ProductA2()
42: End Function
43:
44: Public Overrides Function CreateProductB() As AbstractProductB
45: Return New ProductB2()
46: End Function
47: End Class
48:
49: ' The 'AbstractProductA' abstract class
50: MustInherit Class AbstractProductA
51: End Class
52:
53: ' The 'AbstractProductB' abstract class
54: MustInherit Class AbstractProductB
55: Public MustOverride Sub Interact(a As AbstractProductA)
56: End Class
57:
58: ' The 'ProductA1' class
59: Class ProductA1
60: Inherits AbstractProductA
61: End Class
62:
63: ' The 'ProductB1' class
64: Class ProductB1
65: Inherits AbstractProductB
66: Public Overrides Sub Interact(a As AbstractProductA)
67: Console.WriteLine(Me.[GetType]().Name + " interacts with " + a.[GetType]().Name)
68: End Sub
69: End Class
70:
71: ' The 'ProductA2' class
72: Class ProductA2
73: Inherits AbstractProductA
74: End Class
75:
76: ' The 'ProductB2' class
77: Class ProductB2
78: Inherits AbstractProductB
79: Public Overrides Sub Interact(a As AbstractProductA)
80: Console.WriteLine(Me.[GetType]().Name + " interacts with " + a.[GetType]().Name)
81: End Sub
82: End Class
83:
84: ' The 'Client' class. Interaction environment for the products.
85: Class Client
86: Private _abstractProductA As AbstractProductA
87: Private _abstractProductB As AbstractProductB
88: ' Constructor
89: Public Sub New(factory As AbstractFactory)
90: _abstractProductB = factory.CreateProductB()
91: _abstractProductA = factory.CreateProductA()
92: End Sub
93: Public Sub Run()
94: _abstractProductB.Interact(_abstractProductA)
95: End Sub
96: End Class
See also:
Creational Patterns
- Abstract Factory in VB.NET - Creates an instance of several families of classes.
- Builder in VB.NET - Separates object construction from its representation.
- Factory Method in VB.NET - Creates an instance of several derived classes.
- Prototype in VB.NET - A fully initialized instance to be copied or cloned.
- Singleton in VB.NET - A class of which only a single instance can exist.
- Adapter in VB.NET - Match interfaces of different classes
- Bridge in VB.NET - Separates an object???s interface from its implementation
- Composite in VB.NET - A tree structure of simple and composite objects
- Decorator in VB.NET - Add responsibilities to objects dynamically
- Facade in VB.NET - A single class that represents an entire subsystem
- Flyweight in VB.NET - A fine-grained instance used for efficient sharing
- Proxy in VB.NET - An object representing another object
- Chain of Resp. in VB.NET - A way of passing a request between a chain of objects
- Command in VB.NET - Encapsulate a command request as an object
- Interpreter in VB.NET - A way to include language elements in a program
- Iterator in VB.NET - Sequentially access the elements of a collection
- Mediator in VB.NET - Defines simplified communication between classes
- Memento in VB.NET - Capture and restore an object's internal state
- Observer in VB.NET - A way of notifying change to a number of classes
- State in VB.NET - Alter an object's behavior when its state changes
- Strategy in VB.NET - Encapsulates an algorithm inside a class
- Template Method in VB.NET - Defer the exact steps of an algorithm to a subclass
- Visitor in VB.NET - Defines a new operation to a class without change
Comments (
)
Link to this page:
//www.vb-net.com/ProgramTheory/AbstractFactory.htm
<SITEMAP> <MVC> <ASP> <NET> <DATA> <KIOSK> <FLEX> <SQL> <NOTES> <LINUX> <MONO> <FREEWARE> <DOCS> <ENG> <CHAT ME> <ABOUT ME> < THANKS ME> |