Class Diagramm Problem

Pages: 12
Hello Guys I have again a small Problem .

Can somebody give me some Ideas how the Class Diagramm should look for this task?

It feels not so easy for me
For a statistical evaluation of road traffic, vehicles and the persons involved are to be recorded in an object-oriented software application. For this purpose, the vehicle categories and persons listed below are to be modeled in the form of a UML class diagram.
Create all necessary classes. If you can generalize properties, group them into generalization classes.
Note: You do not need to list any attributes or methods in the class diagram; class names, class relationships, and cardinalities suffice. A class should be displayed as shown in the figure on the right.
Vehicle categories:
• car
• bus
• Bicycle
• tram
Involved persons:
• driver
• Passenger
Assignment of persons:
Each vehicle is assigned exactly one driver, the drivers can change. However, we regard the driver as part of the vehicle, i. E. the vehicle "has" a driver. The number of passengers is as shown below; if provided, the corresponding vehicle "knows" its passers-by.
Bus: max. 60 passengers bike: no passenger
Car: max. 4 passengers Tram: max. 120 passengers
The old adage is, nouns are your objects, verbs are your methods.

Then you need to decide on the relationships, association, inheritance, composition.
https://www.pic-upload.de/view-35435897/Bildschirmfoto2018-06-05um21.05.54.png.html


Can I do it so ?

You can also correct if you want please .

Iam not so fit in the topic
¿what's the meaning of the lines car--bus and train--bus?

> bike: no passenger
and yet you do have a line from passenger to bike.


¿what're the differences between car, bus and train?
only the line means assoziation. Is it right ?

bike : driver Should I make aggregation from driver to bycycle ?

¿what're the differences between car, bus and train?

They are different kind of Machines
Should I use heredity?
For a statistical evaluation of road traffic, vehicles and the persons involved are to be recorded
.

Then it goes on to say:
Vehicle categories:
• car
• bus
• Bicycle
• tram
Involved persons:
• driver
• Passenger


So from this, what are your objects, and what are the inheritance relationships?
The objects are like on my sketch car , bycycle ,tram and bus ?

Inheritance : driver , passenger ?

Or is my sketch wrong ?
The objects are like on my sketch car , bycycle ,tram and bus ?
Yes.

Or is my sketch wrong ?
To my mind, your sketch is wrong.

They told you explicitly, car, bus, bycycle and tram are types of vehicle. And similarly, driver and passenger are types of person. These are your objects.

Inheritance is the means of representing polymorphism (i.e. more than one type). So, a bus has type bus, but also vehicle. In other words, a bus is a special kind of vehicle. In OO terms, bus inherits from vehicle.
https://yuml.me/diagram/scruffy/class/[vehicle]%5E-[bus],[vehicle]%5E-[car]
I think now my sketch is a little better but I am not sure if I might could have solved the task better .

I would be happy ,if you could correct my sketch.

https://www.pic-upload.de/view-35452473/g1.png.html

What would you say ?
> only the line means assoziation. Is it right ?
I'm asking what relationship do you see between those two classes
in your last design you've got a line between driver and person, ¿what does that line represent?


in the assignment say «Each vehicle is assigned exactly one driver» ¿where's that relationship on your diagram? you've got `vehicle' and `driver' classes, but no line between them.
you've got both composition and agregation between `driver' and `bicycle' ¿why?


> And similarly, driver and passenger are types of person
I would say that those are roles that a person may take
https://www.pic-upload.de/view-35456164/Bildschirmfoto2018-06-10um00.05.01.png.html


Here it is in german .

That are the meanings of my lines and so on .

Can you understand my diagramm now better ?

vererbung = heredity
Last edited on
I know how to read UML, thank you

suppose you've got
Person -- Books
that could mean «person wrote these books»
or you may have
Node -- Node
meaning «these nodes are connected»

going back to your diagram, you've got an assoziation between `passenger' and `driver', I'm asking what assoziation did you see.
I know how to read UML, thank you
Hahah ok.

going back to your diagram, you've got an assoziation between `passenger' and `driver', I'm asking what assoziation did you see.

I mean the assoziation that the driver knows for example the passengers and the passengers know the driver.

But in the train for example its a little tricky because the passenger doesnt really know the passenger ? He not even sees him.

Would you say that I should let the assoziation away between them ?

Should I make a <- between driver and passenger (heridate)?Or is it enough when driver and passengers heridate from Person ?
Last edited on
One of the cool things about OO is that you reuse stuff that's already been written, and so, not rewrite it for yourself. One of the ways to do that is thru inheritance, another is composition.

So when defining relationships between two hierarchies, it's best if it's done between the parents if at all possible, because all the children pick up this work for free, or some of it.

All your vehicles (bus, tram bike, car) have a 1-1 relationship with a driver, and a 0 or more relationship with passenger.

Your UML diagrams are really noisy because you're not recognizing the relationships are between vehicle and driver/passenger.
All your vehicles (bus, tram bike, car) have a 1-1 relationship with a driver, and a 0 or more relationship with passenger.


Should I erase the one an one Relationship and make a aggregation from vehicle to passenger and driver ?

Or is it enough to make only a aggregation from vehicle to Person?



Is the komposition from Vehicle to Person wrong?
It can't be person because different subclasses of person (driver, passenger) have different relationships.

So, although driver and passenger will be shown as subclasses of person, they have seperate relationships to all vehicles, not individual ones.

You'll see that your diagram will become a lot simpler as a result.

[EDIT]
Is the komposition from Vehicle to Person wrong?
Yes. A vehicle isn't composed of persons, it has associations with persons. Actually, it has a 1-1 relationship with driver and 0-many relationship with passenger.

For example, a bike will have 1 driver and 0 passengers.
Last edited on
https://www.pic-upload.de/view-35482028/Bildschirmfoto2018-06-15um00.15.37.png.html


I have made a new sketch now .

Is that now better ?

I forgot to paint bycicle.

Byciecle has aggregation to driver ?

Last edited on
I would have thought that train was a vehicle. We've been over this before.

You're right, you left out bike. You need to include it.

You've used aggregation as the relationship to driver and passenger. It's not that strong, we discussed association previously. You also need to show the multiplicity.

This is where I think your confusion manifests, I think. A bus is a vehicle. So all the properties, including associations and inheritance, of vehicle also apply to bus. This is a really important principle. It's called polymorphism. A bus is a bus, but it's also a vehicle.

Vehicle has relationships with passenger and driver. All these relationships also apply to bike, bus, car and train because they inherit vehicle. That being the case, you should not have extra associations from passenger to train and bus, these relationships are already described.
Last edited on
I hope that the sketch is now better ?
https://www.pic-upload.de/view-35483346/Bildschirmfoto2018-06-15um11.41.31.png.html

In School they dont really teach us anything ,so that we have to learn almost by ourselves .

Thats why I am also very greatfull for your help


I made a Aggregation from bike to Driver because the bike has only a driver not a passenger ?

I made still also a inhetitance from bike to vehicle ?
Should I also make a inheritance line <- from vehicle to Train?
Last edited on
In School they dont really teach us anything ,so that we have to learn almost by ourselves.
It's difficult, but you'll eventually have a eureka moment when it all snaps into place. When I was learning this stuff, there wasn't much around, just James Rumbaugh's book on OMT, so I understand your position.

I made a Aggregation from bike to Driver because the bike has only a driver not a passenger?
Aggregation is a very strong kind of association. For example, a car has to have wheels, that's aggregation. Whereas a car has a driver (when in use), that's association.

As I said, a train already has an association to passenger, because it inherited that relationship from vehicle. It's wrong to draw a separate association directly between train and passenger in this case.

The association of passenger to vehicle means, "all types of vehicles have passengers". It gets tricky when we try to apply this to bike, so we say, "all types of vehicles have zero or more passengers". And that covers bikes, buses, cars and trains, ... all of them. That's what inheritance gives you, reuse.

I made still also a inhetitance from bike to vehicle?
We've been over this before. Yes, a bike is a vehicle.

Should I also make a inheritance line <- from vehicle to Train?
Again, yes. A train is a vehicle.
Last edited on
Pages: 12