How should I store a value based on two objects in Java? -


i have objects, lets call them person objects. have other objects, lets call them relationship objects.

i want able assign relationship object between 2 person objects, i'm not sure way go is.

i thinking of maybe giving each person object id , creating 2d array of relationship objects using person object id key values.

i'm not sure if that's best approach though array have lot of null values wherever there isn't relationship between 2 person objects.

@makoto's idea. alternatively, sounds me litte bit more natural have relationship object hold 2 person objects passed e.g. constructor arguments. you'll need track relationship objects because they'll have knowledge both persons parts of it.

class relationship { person firstperson; person secondperson;    public relationship(person firstperson, person secondperson) {     this.firstperson = firstperson;     this.secondperson = secondperson; } 

alternatively can use public method pass reference person objects if don't want them passed via constructor:

public void setpersons(person firstperson, person secondperson) {   this.firstperson = firstperson;   this.secondperson = secondperson; } 

Comments

Popular posts from this blog

asp.net mvc - SSO between MVCForum and Umbraco7 -

Python Tkinter keyboard using bind -

ubuntu - Selenium Node Not Connecting to Hub, Not Opening Port -