-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBridge.cpp
69 lines (59 loc) · 1.57 KB
/
Bridge.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
/**
* \file Bridge.cpp
* \brief Bridge allows two implementations to vary independently
*
* \review
*
* In this case, the implementations of message and recipient are independent,
* but combine to output "Hello world!"
*/
#include <StdStream/StdStream.h>
#include <StdTest/StdTest.h>
#include <Stl.h>
//--------------------------------------------------------------------------------------------------
class IMessage
{
public:
virtual ~IMessage() = default;
virtual void sendTo(const std::string &) = 0;
};
//--------------------------------------------------------------------------------------------------
class Hello :
public IMessage
{
public:
void sendTo(const std::string &a_name) override
{
std::cout << "Hello " << a_name << "!" << std::endl;
};
};
//--------------------------------------------------------------------------------------------------
//--------------------------------------------------------------------------------------------------
class IRecipient
{
public:
virtual ~IRecipient() = default;
virtual void send(IMessage &) = 0;
};
//--------------------------------------------------------------------------------------------------
class World :
public IRecipient
{
public:
void send(IMessage &a_msg) override
{
a_msg.sendTo("world");
};
};
//--------------------------------------------------------------------------------------------------
int main()
{
Hello hello;
World world;
world.send(hello);
return 0;
}
//--------------------------------------------------------------------------------------------------
#if OUTPUT
Hello world!
#endif