C++/CLI
/**//*
(C) OOMusou 2007 http://oomusou.cnblogs.com
Filename : DP_AdapterPattern_ObjectAdapter_Classic.cpp
Compiler : Visual C++ 8.0 / C++/CLI
Description : Demo how to implement Object Adapter Classic.
Release : 07/15/2007 1.0
*/
#include "stdafx.h"
using namespace System;
interface class ITarget {
void request();
};
ref class Adaptee {
public:
void specificRequest();
};
void Adaptee::specificRequest() {
Console::WriteLine("Hello Adaptee!!");
}
ref class Adapter : public ITarget {
protected:
Adaptee^ _adaptee;
public:
Adapter() : _adaptee(nullptr) {}
Adapter(Adaptee^ adaptee) : _adaptee(adaptee) {}
public:
virtual void request();
};
void Adapter::request() {
if (_adaptee != nullptr)
_adaptee->specificRequest();
}
int main() {
Adapter^ adapter = gcnew Adapter(gcnew Adaptee);
adapter->request();
}
VB
'
'(C) OOMusou 2007 http://oomusou.cnblogs.com
'Filename : DP_AdapterPattern_ObjectAdapter_Classic.vb
'Compiler : VB 9
'Description : Demo how to implement Object Adapter Classic.
'Release : 07/15/2007 1.0
'
Imports System
Interface ITargetInterface ITarget
Sub request()Sub request()
End Interface
Class AdapteeClass Adaptee
Public Sub specificRequest()Sub specificRequest()
Console.WriteLine("Hello Adaptee!!")
End Sub
End Class
Class AdapterClass Adapter
Implements ITarget
Protected _adaptee As Adaptee
Public Sub New()Sub New(Optional ByRef adaptee As Adaptee = Nothing)
_adaptee = adaptee
End Sub
Public Sub request()Sub request() Implements ITarget.request
If _adaptee IsNot Nothing Then
_adaptee.specificRequest()
End If
End Sub
End Class
Class ClientClass ClIEnt
Shared Sub Main()Sub Main()
Dim adapter As ITarget = New Adapter(New Adaptee())
adapter.request()
End Sub
End Class