Adapter in VB.NET
Match interfaces of different classes
ReturnConvert the interface of a class into another interface clients expect. Adapter lets classes work together that couldn't otherwise because of incompatible interfaces. These incompatible classes may come from different libraries or frameworks.
![](/ProgramTheory/Adapter.gif)
![](/ProgramTheory/Adapter1.gif)
Please download project with this source code from https://github.com/ViacheslavUKR/StandardDisignOopPattern
1: ' Adapter Design Pattern.
2: ' See description in //www.vb-net.com/ProgramTheory/Adapter.htm
3: Class MainApp
4: ' Entry point into console application.
5: Private Shared Sub Main()
6: ' Create adapter and place a request
7: Dim target As Target = New Adapter()
8: target.Request()
9: ' Wait for user
10: Console.ReadKey()
11: End Sub
12: End Class
13:
14: ' The 'Target' class
15: Class Target
16: Public Overridable Sub Request()
17: Console.WriteLine("Called Target Request()")
18: End Sub
19: End Class
20:
21: ' The 'Adapter' class
22: Class Adapter
23: Inherits Target
24: Private _adaptee As New Adaptee()
25: Public Overrides Sub Request()
26: ' Possibly do some other work
27: ' and then call SpecificRequest
28: _adaptee.SpecificRequest()
29: End Sub
30: End Class
31:
32: ' The 'Adaptee' class
33: Class Adaptee
34: Public Sub SpecificRequest()
35: Console.WriteLine("Called SpecificRequest()")
36: End Sub
37: End Class
![](/ProgramTheory/Adapter2.gif)
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 (
)
![](http://forum.vb-net.com/GetTopicCount.png?id=24F779DB-606C-4983-88ED-90FDDB45D43B)
Link to this page:
//www.vb-net.com/ProgramTheory/Adapter.htm
<SITEMAP> <MVC> <ASP> <NET> <DATA> <KIOSK> <FLEX> <SQL> <NOTES> <LINUX> <MONO> <FREEWARE> <DOCS> <ENG> <CHAT ME> <ABOUT ME> < THANKS ME> |