Search code examples
inheritancedesign-patternsinterfaceumlclass-diagram

A Design pattern suitable for the case


I have the UML diagram below (sorry if the picture does not have many informations).

enter image description here So what I have is

IRE Interface which is implemented by RE class. IRD Interface which is implemented by RD class (and this latter extends RE). IRM Interface which is implemented by RM class (and this latter extends RE).

So is there a suitable Design Pattern to represent this digaram?

Thank you in advance.


Solution

  • This is not the right approach

    First of all, design patterns do not represent or implement UML class diagrams. It's the other way round: an UML diagram represents the structure of a design pattern.

    According to Christopher Alexander, the source of inspiration of Gamma et al. a design pattern:

    describes a problem which occurs over and over again in our environment, and then describes the core of the solution to that problem, in such a way that you can use this solution million times over without ever doing it the same way twice

    The UML class diagram represents the structure of a solution. It does not tell what problem the solution tries to solve, nor how it's go to solve it. Furthermore some design patterns have a very similar structure and only the behaviors or the intent can help to make the difference.

    Structural similarity

    This being said, if your diagram is supposed to represent a design pattern, but you don not remember which one, it is probably the adapter, and more precisely a variant based on inheritance:

    • RE_Impl is adaptee, that is a class with an existing interface, that needs to be adapted
    • IRM and IRD are the target interfaces to which RE_Impl has to be adapted.
    • RM_Impl and RD_Impl are adapters that make the adaptation work.

    However, this is only a guess, because the pattern is not defined by its structure. The intent of the adapter is to convert one interface into another one. So, if the interfaces IRM and IRD are offering something totally unrelated to IRE, it would not be an adapter at all.