Search code examples
c#design-patternsfacade

Implementing a Subsystem Communication Design Pattern


I am looking for an appropriate design pattern for the following:

I have the following system structure:

MainApplication
    SubSystem1
    SubSystem2
    SubSystem3

Where the MainApplication initializes each subsystem,

    SubSystem1 s1;
    SubSystem2 s2;
    SubSystem3 s3;

    public MainApplication()
    {
        s1 = new SubSystem1();
        s2 = new SubSystem2();
        s3 = new SubSystem3();
    }

and each subsystem should be able to communicate with one another.

Within each subsystem how can I call a method from another subsystem? For example in s1

    public SubSystem1()
    {
        s2.Method1();
        s3.Method2();
    }

Would a Facade Design Pattern work here? If so, how would it be implemented? If not which design pattern should be used for this scenario?


Solution

  • This pretty much depends on the kind of communication between the subsystems.

    If it is abstract, i.e. the subsystems do not actually have to know about each other, a publish-subscribe based messaging mechanism may be appropriate. See https://en.wikipedia.org/wiki/Publish/subscribe for an introduction, but i think the concept should be fairly straight-forward.

    If, on the other hand, the subsystems really have to know each other in a concrete way, why are they subsystems in the first place? Making this kind of partitioning indicates that there is indeed a separation of concerns, so finding an abstract interface should not be that hard. If it is, maybe you should reconsider your subsystem responsibilities.