UML and Inheritance: A Tutorial on Classes, Interfaces, and Relationships, Exams of Object Oriented Programming

This tutorial focuses on classes, interfaces, and inheritance using UML diagrams and standards. Topics include examining relationships between classes, identifying association, aggregation, and composition relationships, and creating class diagrams for various classes. Students will learn to answer questions about a system using UML and understand the different types of relationships.

Typology: Exams

2021/2022

Uploaded on 09/12/2022

stifler_11
stifler_11 🇬🇧

4.6

(9)

272 documents

1 / 6

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
Tutorial 6 – Inheritance and UML
This week we will look at classes, interfaces and abstraction, with a particular focus on inheritance.
We’ll use UML diagrams and standards to understand and answer questions about a system.
1: Examine the following simple relationship in the following diagram:
a. What type of diagram is this?
b. What is the relationship between the Rugby and Match Classes?
c. What is the multiplicity between Match and Player?
d. What type of class do you think Match is likely to be?
pf3
pf4
pf5

Partial preview of the text

Download UML and Inheritance: A Tutorial on Classes, Interfaces, and Relationships and more Exams Object Oriented Programming in PDF only on Docsity!

Tutorial 6 – Inheritance and UML

This week we will look at classes, interfaces and abstraction, with a particular focus on inheritance. We’ll use UML diagrams and standards to understand and answer questions about a system. 1: Examine the following simple relationship in the following diagram: a. What type of diagram is this? b. What is the relationship between the Rugby and Match Classes? c. What is the multiplicity between Match and Player? d. What type of class do you think Match is likely to be?

Expressive Relationships in UML

The following UML class diagram describes a way to model sea ports and large ships. We’ll be examining this example in detail as it includes the association, aggregation, composition and interface relationships.

  1. Name two classes that have an Association relationship
  2. Name two classes that have an Aggregation relationship 4: Name two classes that have a Composition relationship
  1. Class Diagrams Create class diagrams for: a.) The Sphere class above public class Sphere { private double r; private double[] loc = new double[3]; private static int count = 0; public Sphere(double x, double y, double z, double r) { … } public double surfaceArea() { return 4dMath.PI(rr); } public double volume(){ return (4d/3d)Math.PI(rr*r); } public int getCount(){ return count; } }

public class Car { private int year; private String make; private double price; private double currentSpeed; private String currentGear; public Car(int year, String make, double price, double currentSpeed, String currentGear) { … } public double getCurrentSpeed() { return currentSpeed; } public void incrementSpeed(double speed){ currentSpeed+= speed; } public String getCurrentGear(){ return currentGear; } } b.) The Car class above Now create the following class diagrams, drawing the appropriate associations and multiplicities between classes: c.) There is a Lecturer and Course class. Each lecturer has a name and a list of courses they are teaching, which can be zero or more. Each course has a name, course number and room and must be taught by exactly one Lecturer.