Chain of Resp. in VB.NET
A way of passing a request between a chain of objects
ReturnAvoid coupling the sender of a request to its receiver by giving more than one object a chance to handle the request. Chain the receiving objects and pass the request along the chain until an object handles it. Chain of Responsibility pattern with several linked objects (the Chain) are offered the opportunity to respond to a request or hand it off to the object next in line.
Please download project with this source code from https://github.com/ViacheslavUKR/StandardDisignOopPattern
1: ' Chain of Responsibility Design Pattern.
2: ' See description in //www.vb-net.com/ProgramTheory/ChainOfResp.htm
3: Class MainApp
4: ' Entry point into console application.
5: Public Shared Sub Main()
6: ' Setup Chain of Responsibility
7: Dim h1 As Handler = New ConcreteHandler1()
8: Dim h2 As Handler = New ConcreteHandler2()
9: Dim h3 As Handler = New ConcreteHandler3()
10: h1.SetSuccessor(h2)
11: h2.SetSuccessor(h3)
12: ' Generate and process request
13: Dim requests As Integer() = {2, 5, 14, 22, 18, 3, 27, 20}
14: For Each request As Integer In requests
15: h1.HandleRequest(request)
16: Next
17: ' Wait for user
18: Console.ReadKey()
19: End Sub
20: End Class
21:
22: ' The 'Handler' abstract class
23: MustInherit Class Handler
24: Protected successor As Handler
25: Public Sub SetSuccessor(successor As Handler)
26: Me.successor = successor
27: End Sub
28: Public MustOverride Sub HandleRequest(request As Integer)
29: End Class
30:
31: ' The 'ConcreteHandler1' class
32: Class ConcreteHandler1
33: Inherits Handler
34: Public Overrides Sub HandleRequest(request As Integer)
35: If request >= 0 AndAlso request < 10 Then
36: Console.WriteLine("{0} handled request {1}", Me.GetType.Name, request)
37: ElseIf successor IsNot Nothing Then
38: successor.HandleRequest(request)
39: End If
40: End Sub
41: End Class
42:
43: ' The 'ConcreteHandler2' class
44: Class ConcreteHandler2
45: Inherits Handler
46: Public Overrides Sub HandleRequest(request As Integer)
47: If request >= 10 AndAlso request < 20 Then
48: Console.WriteLine("{0} handled request {1}", Me.GetType.Name, request)
49: ElseIf successor IsNot Nothing Then
50: successor.HandleRequest(request)
51: End If
52: End Sub
53: End Class
54:
55: ' The 'ConcreteHandler3' class
56: Class ConcreteHandler3
57: Inherits Handler
58: Public Overrides Sub HandleRequest(request As Integer)
59: If request >= 20 AndAlso request < 30 Then
60: Console.WriteLine("{0} handled request {1}", Me.GetType.Name, request)
61: ElseIf successor IsNot Nothing Then
62: successor.HandleRequest(request)
63: End If
64: End Sub
65: 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/ChainOfResp.htm
<SITEMAP> <MVC> <ASP> <NET> <DATA> <KIOSK> <FLEX> <SQL> <NOTES> <LINUX> <MONO> <FREEWARE> <DOCS> <ENG> <CHAT ME> <ABOUT ME> < THANKS ME> |