I have two classes. "System" and "Bluetooth". I want to have a really loose coherency between these two classes as they should be able to exist or not without depending on each other's existence.
system class should be able to notify the Bluetooth class when data is available to be sent by Bluetooth and vice versa, the Bluetooth class should be able to notify the System class when a data is received by Bluetooth and is ready to be read;
so first I came up with an idea to implement it using observer design pattern since it is simple and fast.
I used template based observer pattern. but I couldn't figure out how to make it two-way (i.e. both system and Bluetooth classes should be both subjects and observers at the same time to be able to observe each other).
the code that I imagined for it:
int main
{
System mySystem();
Bluetooth myBluetooth();
mySystem.attach(myBluetooth);
myBluetooth.attach(mySystem);
.
.
.
return 0;
}
main
is actually the system. I haven't done any programming to manage bluetooth connections, though, so my comments might be completely irrelevant.