Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java design / object oriented design issue

Tags:

java

oop

I have a design dilemma I want to share with you guys: I have a class with various member variables that represents a person. One of the members is the home location of the person in coordinates. This class is persisted in a MySQL database.

The issue I have is that I want to have a list of people that are within a certain radius from the recorded distance from the specified person.

I successfuly created an SQL query that returns a result set with the person's details, and its distance from the pin point. But now is the problem: what's the best way to save this data in Java? Saving the distance inside the person class's members is not good, because the distance is not relevant to the person object. I thought about creating a two dimenesional array which holds the person in the first column and the data in the other. Another option I thought is to create a container object with two values, the person and the distance.

What do you think is the most efficient and "object oriented way" of doing that?

like image 838
stdcall Avatar asked Oct 17 '11 17:10

stdcall


2 Answers

It looks like a job for a Map<Person, Double>.

like image 119
toto2 Avatar answered Oct 03 '22 03:10

toto2


I would provide a connection class that holds the distance and person information.

class PinPoint
{
    private double x; // Assuming
    private double y;

    public List<Connection> getConnections(double radius)
    {
        // Return a list of connections with the person and distance information
    }
}

class Connection
{
    private double distance;
    private Person person;
}

That way you can add more things in the connection class later on, too. If you don't need it a simple map might suffice, too.

like image 42
Daff Avatar answered Oct 03 '22 05:10

Daff