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:
doctor : Doctor
dateAdmitted : Date
dateDischarged : Date
In UML models, attributes represent the information, data, or properties that belong to instances of a classifier. A classifier can have any number of attributes or none at all. Attributes describe a value or a range of values that instances of the classifier can hold.
James Rumbaugh has written, "Basically, attributes are for representing relationships between objects and values without identity, whereas associations are for representing relationships between objects and other objects" (Rumbaugh 1996).
In UML models, an association is a relationship between two classifiers, such as classes or use cases, that describes the reasons for the relationship and the rules that govern the relationship. In UML diagrams, an association class is a class that is part of an association relationship between two other classes.
UML provides mechanisms to represent class members, such as attributes and methods, and additional information about them like constructors.
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:
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:
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:
UPDATE (after the comments)
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).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With