0% found this document useful (0 votes)
71 views14 pages

Searching Earthquake Data: Relationships Between Classes

The document discusses the QuakeEntry and Location classes used to represent earthquake data. QuakeEntry is an immutable POJO that has a Location field and constructor that initializes its fields. Location represents a latitude and longitude and has behavior like distance calculation. QuakeEntry has a has-a relationship with Location by storing it as a field and instantiating it in its constructor.

Uploaded by

Mouloud HAOUAS
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
71 views14 pages

Searching Earthquake Data: Relationships Between Classes

The document discusses the QuakeEntry and Location classes used to represent earthquake data. QuakeEntry is an immutable POJO that has a Location field and constructor that initializes its fields. Location represents a latitude and longitude and has behavior like distance calculation. QuakeEntry has a has-a relationship with Location by storing it as a field and instantiating it in its constructor.

Uploaded by

Mouloud HAOUAS
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Searching Earthquake Data

Relationships Between Classes


The QuakeEntry Class
• QuakeEntry class is essentially a POJO
• Plain Old Java Object — but here cannot
create object without all characteristics

public class QuakeEntry {

private Location myLocation;


private String title;
private double depth;
private double magnitude;

public QuakeEntry(…){

}

The QuakeEntry Class
• QuakeEntry class is essentially a POJO
• Plain Old Java Object — but here cannot
create object without all characteristics
• No default/parameterless constructor

public QuakeEntry(double lat, double lon, double mag,


String t, double d) {
myLocation = new Location(lat,lon);
magnitude = mag;
title = t;
depth = d;
}
The QuakeEntry Class
• QuakeEntry class is essentially a POJO
• Plain Old Java Object — but here cannot
create object without all characteristics
• No default/parameterless constructor
• Immutable with getters()

public class QuakeEntry {


public Location getLocation(){..
public double getDepth() {…
public String getInfo() {…

The QuakeEntry Class
• QuakeEntry class is essentially a POJO
• Plain Old Java Object — but here cannot
create object without all characteristics
• No default/parameterless constructor
• Immutable with getters()

public class QuakeEntry {


public Location getLocation(){..
public double getDepth() {…
public String getInfo() {…

The QuakeEntry Class
• QuakeEntry class is essentially a POJO
• Plain Old Java Object — but here cannot
create object without all characteristics
• No default/parameterless constructor
• Immutable with getters()

public class QuakeEntry {


public Location getLocation(){..
public double getDepth() {…
public String getInfo() {…

The QuakeEntry Class
• QuakeEntry class is essentially a POJO
• Plain Old Java Object — but here cannot
create object without all characteristics
• No default/parameterless constructor
• Immutable with getters()
• Reasonable .toString() method
public class QuakeEntry {
public Location getLocation(){..
public double getDepth() {…
public String getInfo() {…

The Location Class
• Many, many contexts: beyond QuakeEntry
• Use simple, functional design for course?
• Use industrial strength design for course?
• We'll adopt Android class
The Location Class
• Many, many contexts: beyond QuakeEntry
• Use simple, functional design for course?
• Use industrial strength design for course?
• We'll adopt Android class
• Latitude and Longitude
• Initialize from source
• Distance from A to B?
• More than state/POJO
• Behavior!
Has-A and Uses-A Relationships
• QuakeEntry object created by Parser
Has-A and Uses-A Relationships
• QuakeEntry object created by Parser
• Location constructor called from QuakeEntry
constructor

private Location myLocation;

myLocation = new Location(lat,lon);


Has-A and Uses-A Relationships
• QuakeEntry object created by Parser
• Location constructor called from QuakeEntry
constructor

private Location myLocation;

myLocation = new Location(lat,lon);


Has-A and Uses-A Relationships
• QuakeEntry object created by Parser
• Location constructor called from QuakeEntry
constructor
• myLocation is instance field in QuakeEntry:
Has-A relationship
private Location myLocation;

myLocation = new Location(lat,lon);


Has-A and Uses-A Relationships
• QuakeEntry object created by Parser
• Location constructor called from QuakeEntry
constructor
• myLocation is instance field in QuakeEntry:
Has-A relationship

• Location used in EarthQuakeClient


• .distanceTo(..)
• QuakeEntry used in EarthQuakeClient too
• getMagnitude(..)

You might also like