UML Class Diagrams and Examples
Here are some examples of UML class diagrams and explanations of their contents. See if you can interpret the last diagram yourself. Refer to Handout #2 for helpwith the UML syntax.
Example #1: Inheritance – Vehicles
This diagram shows an inheritance hierarchy – a series of classes and their subclasses. Its for an imaginary application that must modeldifferent kinds of vehicles such as bicycles, motor bike and cars.
• All Vehicles have some common attributes (speed and colour) and common behaviour (turnLeft, turnRight)• Bicycle and MotorVehicle are both kinds of Vehicle and are therefore shown to inherit from Vehicle. To put this another way, Vehicle is the superclass of both Bicycle and MotorVehicle
• Inour model MotorVehicles have engines and license plates. Attributes have been added accordingly, along with some behaviour that allows us to examine those attributes
• MotorVehicles is the baseclass of both MotorBike and Car, therefore these classes not only inherit the speed and colour properties from Vehicle, but also the additional attributes and behaviour from MotorVehicle
• BothMotorBike and Car have additional attributes and behaviour which arespecific to those kinds of object.
Example #2: Relationships – Students and Courses
This example demonstrates relationshipsbetween classes. It’s from an imaginary application that models university courses.
• Each Course object maintains a list of the students on that course and the lecturer who hasbeen assigned to teach that course
• The Course object has behaviour that allow the adding and removing of students from the course, assigning a teacher, getting a list of the currently assignedstudents, and the currently assigned teacher.
• Teachers are modelled as Lecturer objects. As a lecturer may teach more than one course there is an association between Course and Lecturer. The...
Leer documento completo
Regístrate para leer el documento completo.