(NET) NET (2016)

Adapter in VB.NET

Match interfaces of different classes

Return


Convert 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.







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




See also:
Creational Patterns Structural Patterns Behavioral Patterns

Comments ( )
<00>  <01>  <02>  <03>  <04>  <05>  <06>  <07>  <08>  <09>  <10>  <11>  <12>  <13>  <14>  <15>  <16>  <17>  <18>  <19>  <20>  <21>  <22>  <23
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>