Search code examples
classumldiagramclass-diagram

Representing a grid in UML Class Diagram


I would like to represent a grid for a timetable in a UML class diagram ahead of creating the software, but online resources make this confusing.

I know columns and rows (which is what I want) can be represented like this:

 MyClass
 + <<column>> Monday: String
 + <<column>> Tuesday: String
 + ...
 + <<row>> 9am: String
 + <<row>> 10am: String

The problem with this is that it doesn't act like a grid. From what I understand, this would treat the columns and rows seperately and not like coordinates: e.g. if I wanted to set something for Monday, 9am.

My question is, how could I go about doing this? Is there a step that I'm missing, or am I thinking about this in a completely wrong way?


Solution

  • If you really want to represent timetable by showing it hour by hour you should build your timetable as a (ordered) set of week days which in turns will be build of (ordered again) hours. In such case the diagram will look like that:

    Timetables with enumeration

    Moreover do not represent objects as parts of classes. Use another classes and if it's necessary mark it's multiplicity.

    As a result you'll end up with 3 classes.

    Note also that this is the simplest version. I would also recommend using some enumerators for names of DayOfWeek and for HourOfDay. Your diagram might look like that:

    Timetable - simple

    This is also with the approach that you specifically want to represent the presentation. It's definitely better to build the class for Activities and this part use only for GUI.