Let's say you are trying to model a rent-with-driver service. You have a Driver class to represent the informations about the drivers. Each driver can have one or more (1..*) cars available, represented in a Car class (I guess). Each driver can also insert one or more (1..*) shifts during which they are available (shifts are characterized by an area, a day a starting_time and an ending_time), and for this reason I imagined a Shift class was needed. A User class can search() for available cars in a given area at a given time.
You have to draw the class diagram of this system and the sequence diagram of the search() use case.
How do you represent the Shift class in such scenario?
I mean, all those classes clearly don't represent a single entity, but rather a set of data of that type. Now, for a user or a driver you can easily represent them by taking a single user or a single driver object and they will summarize the behaviour of all of them pretty good. But how do you do this with the Shift class? The search() operation must be done on the whole dataset rather than on a single object and a single object clearly doesn't hold all the information about all the shifts. Plus, surely a shift object doesn't have a getAvailableCars() method, since, again, it hold the informations about a single shift.
It goes without saying that something like this (which is what I come up with until now about the sequence diagram)

looks too simplistic to be correct.
Should I introduce a ShiftsList class and a CarsList class? Should I just treat it as a set of objects in some other way?
I can imagine how I would model a problem like this with an E/R diagram since in that case the Shift entity would be a database's table, which is a set of data by design, but I'm having a really hard time trying to put this in UML.
Your design sounds reasonable, except I would replace User with Driver.
Do not model lists in UML. A list is a way to realize an association with 0..* multiplicity.
The available cars is just a returned Car class with multiplicity 0..*.
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