Reputation: 2519
I have an interface that some components rely on:
interface IFoo {
void DoWork()
}
class Component() {
void Method(IFoo f) {
f.DoWork();
}
}
as well as a concrete implementation of the interface.
I want to abstract away the network communications from the components so that they can either be used either as a fat client or thin client, so I have written a sender/receiver pair that implements and contains the interface respectively:
class Sender : IFoo {
void DoWork() {
// do network stuff to send message
}
}
class Receiver {
IFoo f = ...
void Recieve (...) {
f.DoWork();
}
}
Is there a named design pattern that describes the above abstraction and design? It looks a little bit like an adapter pattern but it is not changing the interface. The receiver by itself could be implemented as a decorator, but that does not describe the sender, or how the two are used in conjunction.
Upvotes: 0
Views: 134
Reputation: 29977
I think that given the motivation, the Adapter pattern (in particular the class variation)is what you want. One adapter can execute the code locally, while anonther Adapter implementation makes a remote call.
I don't fully agree with Waog answer as the motivation of the patterns he mentions is quite different. And also the Adapter pattern goes together with the Dependency Inversion Principle to allow different low level implementation to be swapped.
Upvotes: 0
Reputation: 7255
What you do reminds me of Stubs and Skeletons. Take a look at.
Does it match your problem?
Upvotes: 1