I need to draw an UML class diagram which is made from the following statements.
A house has an address and consists of several rooms. Each room has a size. It can either be a bedroom, a living room, or a kitchen. A house consists of at least one of each kind of rooms.
The last statement is a constraint, and I need to add it in my diagram.
UPD: The whole task was the following.
Draw a UML class diagram representing exactly the following scenario:
A family consists of an arbitrary number of children and one or two parents. Every
family member is a person with a name and an age. Children are able to play games and
parents can go to work and they can cook something in the kitchen. A family lives in a
house which has an address and which consists of several rooms. An arbitrary number
of families can live in a house. Each room has a size. It can either be a bedroom, a living
room, or a kitchen. A house consists of at least one of each kind of rooms. An arbitrary
number of persons sleeps in a bedroom.
In case you wish to keep the Association between House and Room, you could create additional Associations to the individual room types, sub-setting the Room end.
The {subsets Room} means that these should be considered a part of the general Room association.
{subset} can be removed, because if one end of the association {redefine}, then the other must be a {subset}. End Association House (from Kitchen) {redefine} end of the Association House (from Room), because their names are the same.
Related
In my domain model diagram, I have a class Area that is defined by multiple sensors (eg:temperature sensors), but each sensor can be on one area at a time. As I can move the sensors, I can change the sensors to another area, and in the ultimate case delete the area (because an area needs sensors to exist).
Knowing, Area has already and attribute data:Data.
How can i keep track of previous Areas?
eg:
time=0 - Area A has sensors 1,2,3
time = 10- Area A has sensors 2,3
time =20- Area A has sensors 3
I want to be able to go to previous states of the instance, and check which sensors belonged to the area at a certain time t.
Current diagram:
You can use a qualified association with the timestamp as qualifier. This is shown with a small rectangle at the Area end of the association with the text t:Timestamp in it.
PS: In your diagram an Area can exist without Sensors, since the multiplicity is 0..*. You should change it to 1..* if you want this semantics.
The qualifier is an interesting approach. However, it requires to know the precise timestamp of the start of an Area assignment to access the current or an historically associated area. Moreover the history goes in both direction, unlike the qualifier which is inly at one end.
For these reasons the association class would be more suitable:
the association class keeps track of the history, with a begin and end date.
the association with the current period could simply have no end date. Since an association class has reference
semantic (and identity), you could change the end date of the current association, once it’s no longer the current one.
navigation in both direction can take into account the chronology.
The only challenge is to express
the multiplicity constraint at any given time, as the association would become many to many: it’ll be more difficult to tell that there is only one area for a sensor at any given time. Programmatically (for the implementation), it’ll not be a big deal to implement this. But expressing this in OCL, taking into account possibly overlapping intervals it’s more difficult. Fortunately, as qwerty_so indicates in the comments, it’s perfectly valid to express the constraint in plain english.
N.B. additional comparison of an association class and a qualified association for similar problems, here on SE.
Hello,
I am learning UML and I am facing some challenges with the class diagram.
My learning sources don't explain the generalization relationship very well and also the abstract class subject (or I don't understand it enough).
When taking this for example. There is a class person with an attribute ' name' with a generalization relationship to ProjectEmployee.
I see it as Person is the parent and Projectemployee as the child. So the person is a projectemployee as well?
And projectemployee has an aggregation relationship to projectteam. Does this mean that the person is always part of a projectteam?
Is it better to make 'person' an abstract class?
This diagram says that ProjectEmployee is a specialization of the more general Person. In other words, every ProjectEmployee is a Person, but there may be some Person that are not ProjectEmployee
The (shared) aggregation means the same thing as an ordinary association (at least for the current UML specifications, which do not define its semantics). So it means that ProjectEmployee may be associated with a Projectteam. We can’t tell more since multiplicities are not specified in this diagram. Only multiplicities can tell you if a team member must or can belong to a team. For example, 1 on the diamond side means that a member must belong to exactly one team, 1..* that a member must belong to at least one team but can belong to several teams at the same time.
There is no argument here to suggest that Person should be abstract. There is no argument for the contrary either. The question is therefore: what would you want to achieve by making it abstract? For example, do you have some operation that Person should offer, but that could only be defined for subclasses and not for a Person in general? Or do you want to prevent Person to be instantiated?
Given the following situation:
RQ1: A flight can only be carried out by one plane
RQ2: A plane can be assigned to zero or more flights
So I have a class called Flight and a class called Plane.
I don't know if I'm over-thinking the relationship between Flight and Plane though.
So for RQ1, you'd have an association between Flight and Plane, and the multiplicity would be Flight [1] ------ Plane [1]
But then RQ2 comes along and I need an association between Flight and Plane but how do I manage the multiplicities? I think it would be Flight [0...*] ------ Plane [1]
Problem is, doing that creates two classes and two association lines and 2 pairs of/4 individual multiplicity values which doesn't sound right either.
Of course you can. Imagine a self relation from Person to self. One would be Father and one would be Mother (just forget for a moment that this might be different since a not so far past). So you can have as many relations between two classes as needed.
If you use role names, the situation will clear up. So the association for RQ2 would be named assignedFlights. The carriedOutFlight role from RQ1 could also be an index into the assignedFlights (as implementation variant). But of course it can be a different association as well.
CONTEXT: I have an abstract class Student. From this class I derive three concrete classes SchoolStudent, UnderGradStudent, PostGradStudent. I have another class Vehicle. A school student must NOT drive a vehicle however, an undergrad or a postgrad student may or may not drive a vehicle.But every vehicle must be driven by somebody hence the Vehicle class has a reference to a student.
PROBLEM: I have association between classes UnderGradStudent & Vehicle and another association between PostGradStudent & Vehicle. However, I am a little confused about the multiplicity.
As I understand the problem, the UML class diagram should look something like this:
However, I suspect the above diagram suggests that each Vehicle will have one UnderGradStudent as well as one PostGradStudent.
Is the above diagram correct as to what I want to model corresponding to the context?
As you've drawn this UML diagram, it implies (but does not say correctly) that a Vehicle must be driven by both one UnderGradStudent and one PostGradStudent. It also implies that an UnderGradStudent can drive any number of Vehicles and a PostGradStudent can drive any number of Vehicles (at the same time). I don't think that's what you intended. The reason I say "implies" is that you have overlaid two associations on one end. Last I checked, that is invalid UML.
I think you wanted to say that a Vehicle may be driven by up to one Undergrad Student or Postgrad Student. To say that, I recommend the following model:
What this says is:
A valid instance of Student must be one of School Student, Undergrad Student, or Postgrad Student (and not multiply classified)
A valid instance of Allowed Driver must be one of Undergrad Student or Postgrad Student (and not multiply classified)
A Vehicle can be driven by up to one Allowed Driver (at a time)
An Allowed Driver drives up to one Vehicle (at a time)
This describes a valid situation at any point in time, which is really useful. Think of it as a way to evaluate the validity of any frame in a movie.
If you need to record all the drivers of every vehicle ever, you would need to make many changes. A Person actually plays the role of a Student (among other roles, usually), and that role can change over time. You would need to record the start and end time of every role change and the start and end time of every driver / vehicle change. Think of this as recording all the frames in a movie, but without the ability to express the validity of any given frame in the movie. You lose that ability when you relax multiplicities.
You can get the benefits of the "single frame" and the "whole movie" approach by combining all of the associations I mentioned.
Your problem will easily be solved by using a 0..1 multiplicity near the *Student classes from the Vehicle. This will tell the reader that both are allowed to have a related optional vehicle. To avoid both using the same car you need to attach a constraint like this:
Alternatively you can do it the following way:
I'm not good in writing OCL but you could formalize the constraint as well.
After some confusion with mixing use case and class diagrams, managed to clear some doubts and come up with the following class diagram. Felt more comfy with this than use case. Hope am not wrong. Would like some feedback on any errors and improvements on it. Thank you.
Question:
A new library has books, videos, and CDs that it loans to its users. All library material
has a unique identification number and a title. In addition, books have one or more authors,
videos have one producer and one or more actors, while CDs have one or more artists.
The library maintains one or more copies of each library item (book, video or CD). Copies of all
library material can be loaned to users. Reference-only material can only be loaned for a
maximum of two hours and can’t be removed from the library. Other material can be loaned for
up to two weeks. For every loan, the library records the user, the loan date and time, and the
return date and time. For users, the library maintains their name, address and phone number.
Draw a class diagram for the description above.
Class Diagram: link to diagram
Don't use notes for multiplicities 1..*. Edit associations or their ends instead and write it there.
Write multiplicities on ends, not in the middle of the line.
Arrows should be subscribed by names of attributes.
Libraries can have many Videos, books, CD's and so on. So, there multiplicities should be in both ends.
No arrows on the line is the same as arrows on both ends. Check it on the right sides.
Write attributes inside blocks when they are of types not present on the diagram. If they are not, put their names on the opposite ends of the associations, near arrows.
You should use some empty diamonds on the left side.
You should decide the multiplicity of the producer.
Divide Title from Copy. And maybe, from Edition.
Don't mix plural and singular - hold to some system. I use plurals only for collections, but you needn't take it, of course. Plurals in class names are senseless - all classes apart from singletones have many instances.
You don't need toconnect library to CD and Video - they are merely subsets of Books. And books already are connected. The same with three lists in the Library block.
Loan should be connected to Book.
According to standards, loan() is a constructor of the class Loan. It can't be in another class.