How to show Data transfer object on a UML class diagram?

1.4k views Asked by At

How do I show Data transfer object in a UML class diagram? So can someone give an example of a UML class diagram with a DTO.

1

There are 1 answers

3
Christophe On

A data transfer object is in principle an object like any other. As a consequence, you would probably want to represent a DTO class, with all the attributes needed and some operations to convert to and from a data transfer representation (e.g. a data format).

You may have the following additional needs specific to the DTO:

  • to highlight that it's a DTO object and avoid confusion with domain objects, you could use an UML profile with a «DTO» stereotype that you could show above the class name.
  • you could highlight the dependency to the class(es) that the DTO is supposed to transfer.
  • If the DTO contains nested objects, you might have to define classes for them as well, with the related associations.
  • If a DTO just combines one or several objects of a couple of related classes, you could as well just show the related objects as attributes of the DTO with their original type, and if needed, with multiplicity.

In some designs however, the DTO object is not really of a different class: it may just be a different representation of the same objects grouped using some special format/encoding (JSON, XML). In this case, from the design perspective it's not necessary, nor even desirable to create distinct classes: it'd be the same classes, except that the domain objects are "dehydrated" for storage/transport purpose (i.e. attributes/state without behaviors, until objects are properly extracted from the DTO) .