I am trying to learn Adapter Design Pattern UML with C++ and in one of the videos in youtube displayed this content - my issue is translating the UML picture to C++ class / code:
What I really get confused is:
-
The Clinet -------> [solid line] association to interface Target. What does this means generally I have seen classes implementing interface something like Adapter class implementing Target
-
What does the content Adapter is composed with the adaptee means here - if it is containership then does it completely or partially owns it?
Below is the code implementation that I can think of it:
class Target
{
public:
void virtual ServiceA() = 0;
};
class Client : public Target
{
public:
Client(){}
void ServiceA() override {}
};
class Adaptee
{
public:
Adaptee(){}
void ServiceX(){}
};
class Adapter : public Target
{
public:
Adapter(){}
void ServiceA() override {adaptee.serviceX();}
Adaptee adaptee;
};
int main()
{
.....
}
How inside main we would code up? Please explain.
Aucun commentaire:
Enregistrer un commentaire