Hi there,
I've always been wondering what's the best way to model a one-to-many relation between two Java classes and save them into a DB.
For example,
Imagine we have two classes Person and Address where a person might have more than one address, we know that the best way to model this in a relational DB, would be to have two tables
Person(personID,Name) and Address(addressID,personID,city,country, addrType)
So we save as many addresses as we want and associate them with the person ID.
I want to implement this in objects, for example have a person1 as an instance of a Person class, and whenever I want to add an address I instantiate an address1 of class Address and perhaps have a method
person1.addAddress(address1);
I wonder how this could be coded.I have lots of thoughts about implementing this but all are out of the OO scope, and I don't want to implement it using Entity classes or else, I just want thoughts and perhaps an example or anything that could clear my thoughts about it.