Search code examples
umlsequence-diagramflowchart

Representing a class that reads a configuration file


For the following UML diagram, the class Customer reads configuration from a json file to configure various aspects of customer like language, region, etc. Now I am not sure if sequence diagram below in UML can depicts that please or it's supposed to show interactions between classes only? Also if the class is doing logging operation, can this also be added to a sequence diagram please?

enter image description here


Solution

  • The sequence diagram focus on interactions between classes. So if you want to add the reading of the configuration file, you'd have to find with what other class Customer should interact:

    • The easiest way is to simply to insert a self message readConfiguration() . If your configuration process is in a single operation of your class, it's probably the clearest way to show it. Advantage: it will keep the high level of abstraction and hide unnecessary details.

    • Another way would be to have a lifeline for the :FileSystem. This allows to zoom on the details of the opening, reading, seeking operations performed. But wouldn't this be too detailed? After all, your sequence diagram is not meant to program visually. Moreover, this approach would not allow you to indicate that all these reading exchanges are performed in a single operation of your Customer class. So it could even be misleading.

    • You could also consider adding a lifeline :ConfigurationFile. This makes sense if you encapsulate the reading of configuration in a separate class and the diagram reflects this design. By the way, separation of concerns and the single responsibility principle make this a very recommendable approach. Especially if you'd have other classes to configure and you'd like to different policies to read the configuration (read from file, read from the register, read from encrypted file, read from EPROM, etc...)

    Foir the logging operation it's the same. But again, avoid too many details. Add logging if it is really a critical feature of your design because otherwise, you'd quickly clutter the diagrams with unnecessary details that could easily be described in simpler way.