java - What is the correct way to add this field to this entity? -


i have entity

public class location{     private string name;    private final set<string> sublocations = new hashset<string>();     public string getname(){       return name;    }    // corresponding setter     public void addsublocations(string sublocation){       sublocations.add(sublocation);    }    public set<string> getsublocations(){       return sublocations;    } } 

this class populated , stored mongo db collection.

we have requirement of adding new field called "organization_group". logically, belongs under sublocation, add there.

what pasted class right now. best way of adding 'group' child sublocations? create sublocation class?

just need input on this,

thanks!

before answer question, whats difference between location , sub location ? single field name, me both class definitions same.

are aware of composite pattern ? if location class needs represent tree data, should consider using composite pattern.

now answer question, believe thinking in right direction, adding field called organizationgroup new sublocation class right way go situations.


Comments

Popular posts from this blog

html - How to style widget with post count different than without post count -

How to remove text and logo OR add Overflow on Android ActionBar using AppCompat on API 8? -

javascript - storing input from prompt in array and displaying the array -