design-patternsumlclass-diagramabstract-factory

Abstract_factory UML diagram in Wikipedia incorrect?


Referring to the UML diagram depicted in https://en.wikipedia.org/wiki/Abstract_factory_pattern#/media/File:Abstract_factory_UML.svg, one could conclude that ConcreteFactory1 and ConcreteFactory2 are derived from AbstractFactory.

enter image description here

But AbstractFactory is an interface, therefore it must be 'implemented', not 'extended'.

What am I missing?


Solution

  • You are correct: The concrete factories should realize (implement) the interface and not specialize it.

    Part of the confusion comes from GoF which was written in a time where only rare languages provided for "interfaces":

    To add to the confusion, obsolete versions of UML (e.g. UML 1.4, section 3.29.1) gave to interfaces the same semantic as purely abstract classes, providing tolerance for such a mixed notation. But this is no longer the case (and for almost two decades). The current UML definition makes an interface a contract that cannot be inherited by a class but must be implemented/realized instead.

    One simple advice: if wikipedia is wrong, cross check carefully, look for some authoritative sources and correct it :-). In this case you could even refer to alignment with the diagrams in the section "Structure".