The Adapter Design Pattern... Adapter Structure ClassClient Request Target* Adapter SpecificRequest implementation specificRequest Adaptee Convert the interface of a class into anot
Trang 1The Adapter Design Pattern
Trang 2Adapter Structure (Class)
Client
Request()
Target*
Adapter
SpecificRequest() (implementation)
specificRequest()
Adaptee
Convert the interface of a class into another inteface clients expect.
Trang 3Adapter Structure (Object)
Client
Request()
Target*
Request( )
Adapter
adaptee->SpecifricRequest() adaptee
specificRequest()
Adaptee
Trang 4Adapter Consequences
ConstraintStateVariable
ConstraintVariable StateVariable
Trang 5Adapter Implememntation 1
GetChildren(node)
CreateGraphicNode(Node)
Display()
BuildTree(Node n)
GetChildren(node)
CreateGraphicNode(Node)
FileSystemEntity (Adaptee)
GetChildren(n) for each child { AddGraphicNode(CreateGraphi cNode(child)) BuildTree(child)
}
Trang 6Adapter Implementation 2
SetDelegate(Delegate)
Display()
BuildTree(Node n)
CreateGraphicNode(TreeDisplay, Node)
TreeAccessorDelegate* (Target)
GetChildren(TreeDisplay, Node) CreateGraphicNode(TreeDisplay, Node) CreateFile()
DeleteFile()
DirectoryBrowser (Adapter)
FileSystemEntity (Adaptee)
delegate->GetChildren(this, n)
for each child{
AddGraphicNode(
delegate->CreateGraphicNode(this, child)
)
BuildTree(child)
}
delegate
Trang 7Adapter Known Uses
Object*
value:
value
ValueModel*
getBlock setBlock
value:
value
PluggableAdaptor
^ getBlock value:adaptee
adaptee