C++/CLI
/**//*
(C) OOMusou 2007 http://oomusou.cnblogs.com
Filename : DP_AdapterPattern_ClassAdapter_Classic.cpp
Compiler : Visual C++ 8.0 / C++/CLI
Description : Demo how to implement Class 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 Adaptee, public ITarget {
public:
virtual void request();
};
void Adapter::request() {
specificRequest();
}
int main() {
ITarget^ adapter = gcnew Adapter();
adapter->request();
}
VB
'
'(C) OOMusou 2007 http://oomusou.cnblogs.com
'Filename : DP_AdapterPattern_ClassAdapter_Classic.vb
'Compiler : VB 9
'Description : Demo how to implement Class Adapter Classic.
'Release : 07/15/2007 1.0
'
Imports System
Interface ITragetInterface ITraget
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
Inherits Adaptee
Implements ITraget
Public Sub request()Sub request() Implements ITraget.request
specificRequest()
End Sub
End Class
Class ClientClass ClIEnt
Shared Sub Main()Sub Main()
Dim adapter As ITraget = New Adapter()
adapter.request()
End Sub
End Class
執行結果
Hello Adaptee!!
Object Adapter