Search code examples
oopumlclass-diagrammultiplicity

Can we have an interface create objects of another interface in UML Class Diagrams?


I've made the following class diagram with PlantUML. But it feels weird to have a interface instantiate objects of another interface. Is this allowed in UML?

The other approach I see, is to get rid if the interface and have FactoryA create ProductA and so on.

Diagram


Solution

  • It is perfectly legal that an interface creates instances of another interface.

    In UML the interface is a contract. The contract would then mean that instances of a class realizing the first interface shall create instance of classes realizing the second one.

    This may sound very abstract, but in simpler words, it just means that the first interface defines the contract for a set of factory classes. This looks like a simplified variant of the abstract factory pattern

    Remark: the «create» is a usage dependency and not an association, so there should be no multiplicities on its ends. And the keyword should be between «».