Search code examples
inheritanceumlcompositionclass-diagram

UML Classes representation


I'm learning UML and want to create a small restaurant application, that has a menu, dishes contained in menu, products used in dishes. Menu is divided into different types that can contain only of the appropriate type. I suppose that class menu and dishes should be abstract. That's my UML diagram.

enter image description here

How to best display the relationship of abstract classes?


Solution

  • First attempt

    If we look at the requirements, i.e. that Orders are about Dishes, that Dishes are composed of Products, and that Menus are like catalogues of Dishes of some kind, we would come to such a diagram:

    enter image description here

    We'd show only a "relation" between the abstract Dish and the abstract Menu. The specialised dishes and menus inherit this association. It's just that you have to express with a comment on the association the constraint of using dishes compatible with the menu.

    Further reflexions

    The question is if we really need Menu specializations. This would be justified if they'd have very different behaviors.

    Moreover, in your example you assume strict separation of the menu specialization. But what if at a later stage you'd have overlapping menus, e.g. Main menu with vegetarian, vegan and meat dishes, and a Vegan menu with only vegan dishes but for all kind of dishes.

    If the behavior is the same for all the menu specializations and if this is only meant as an arbitrary categorisation (and if moreover, you'd have only one instance per class in practice), then it would be better to make Menu concrete and associate it with a Category class. By the way, you could also associate the abstract Dish to one or several Category, which would allow easier expression of the constraints you wanted.

    Finally, it would be worth to explore the concept of association class and rethink what's between Order and Dish as well as between Dish and Product.