Search code examples
eventsinterfaceumlclass-diagram

How far can we stretch a UML Interface?


First, context: We're developing some applications using QP Framework from quantum leaps. QP is basically an event manager for state machines.

Our approach: Since we're using QP, our modules interact with events and signals (classes/structs and enums) except some very specific modules that interact by methods.

Problem: For those last modules, interfaces are easy, just a collection of all the public methods in said module, however, how about the others? Can we say an interface is a composition of other classes and enumerations?

Since the modules interact by sending/receiving events, both should know what kind of data packets (events) can travel through that interface.

Can we represent an interface like this? or should an interface only be a collection of methods? 2

edit 1: Replying to the comments below, I don't want to say the interface had nested classes, but that the interface would define said classes so they could be used as events, but from your answers, seems using signals would be a better approach. (The ADC:: prefix and the name of the interface are not the same, just some bad naming choices, as the package name was ADC and so was the interface)

edit 2: From the comments and answers below, I had no knowledge of the signal stereotype, so updating the question, I think it would become something like this?

3

This solves the classes and signals problem, however, the enum remain...

My intention was to say the interface would define this keywords, i.e. the module that implements the interface, should define this enum and their values.

Is this the correct approach?


Solution

  • The interface in your diagram is perfectly legit. UML interfaces do not have the constraints of Java interfaces: they can have operations, attributes, and all kind of associations (btw, the aggregation does formally not add any semantics to associations, and you could safely consider to remove the white diamonds), including composition (black diamond).

    However it might not represent what you are looking for: interfaces express a contract. It means that the classes implementing it must provide those attributes and associations, and not that the classes will get all these features by a kind of “inheritance”.

    Moreover, I’m not sure if you try to express some complex interface, or just found no better way to represent event consumption/generation. In the latter cse it would be an overcomplex and misleading approach.

    For event based design, you may be interested in using signals. Signals are like classes, but there are UML elements to express the ability to process a family of events, and/or to generate events. It moreover facilitates the link between sequence diagrams and class diagrams, as a message can correspond directly to an event instance.