Merret Ferret
Merret Ferret

Reputation: 1

How would an implementation for this UML class diagram look like?

UML Diagram

abstract class Activity extend Measurement extends Location{

private DateTime timestamp;
private int heartRate;

private double latitude;
private double longitude;
private double elevation; 
}

I wonder if maybe it should look like this inside, with classes repeated:

public class Measurement{
private DateTime timestamp;
private int heartRate;
}

public class Location{
private double latitude;
private double longitude;
private double elevation;
}

Should it be only all fields or classes inside as well?

Upvotes: 0

Views: 208

Answers (1)

Ryo Shiina
Ryo Shiina

Reputation: 568

You might have misunderstood the black filled diamond, which is not an inheritance but a composition. Your Activity class has no any extends but it contains one instance of Measurement, which has to be instanciated inside Activity.

public class Activity {
    private Measurement measurement = new Measurement();
}

It should look like this I guess (since I see no constructor in your diagram), although I don't know if measurement should be private or public from your UML diagram.

A better practice of this is to instanciate measurement in Activity's constructor, so I'll just leave this link here which might help you to understand how to do it.

EDIT : I forgot to mention, your other classes look correct, but don't forget the association relationship between Measurement and Location : Measurement has to know that Location exists. You'll surely have to keep this in mind when adding methods to your current classes.

Upvotes: 1

Related Questions