Question

Now i have two classes, named patient and doctor:

Patient() {
     public:
        //functions here
    private:
    Doctor doctor;
    Date dateAdmitted;
    Date dateDischarged;
}

Doctor() {
    public:
    //functions here
    private:
    //data members here
}

In my UML class Diagram for patient class, do i need to include the doctor and date as attribute? or i just represent them by linking them as association?

If attribute it should be like:

Patient

doctor : Doctor

dateAdmitted : Date

dateDischarged : Date

Was it helpful?

Solution

According to UML syntactical rules, both solutions are valid - both class attributes and associated classes are so called class properties and can be shown as attributes (inside the class) or as separate classes, linked via association. For both these class features you can define name, multiplicity, scope, etc. Please refer to UML spec for detailed technical information.

However, the common practice if the following:

  • if the property is basic data type (int, boolean, date, etc) -> show it inside a class, as attribute
  • if the property is full fledged class -> show it as a separate class entity and use association to display their relationship

This practice make sense, as "int", "boolean" or "date" do not have their own custom properties and it is enough to show them inside a class (withoult losing information about them). Classes, on the other side, have their own features (attributes, methods and own associations, generalizations, etc) and therefore "deserve" more space on the diagram.

Concluding with the direct answer to your question: show Doctor as a separate class on the diagram, connected with Patient via association (note the property name displayed as associationEnd name). Keep both dates inside the Patient class:

enter image description here

The following diagram is equivalent and valid, but you might agree that the first one is visually clearer (imagine some atts, methods and relationships or the Doctor class) and therefore recommended:

enter image description here

UPDATE (after the comments)

enter image description here

Note: Composition is used for Dates, to reflect a strong relationship of the Whole-Part kind and the fact that these Dates cannot be unlinked from their context. The other association (Patient-Doctor) is a common assotiation and the corresponding link can be broken anytime (for example to change a Patient's Doctor).

OTHER TIPS

In UML, you would model relationships between classes as an association. Attributes should be for data types.

That they will most likely end up as fields in e.g. Java does not play a role at this stage yet.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top