I have just started doing OOP design. My experience has been in RDBMS. Where we work with tables, relation between them defined using foreign keys. Can anyone pl. help in designing classes for a simple case here. There are two tables (states, districts). Districts contains stateId as foreign key. So state to district 1-many relation is there. Such things how do we design in oops. Thanx in advance

Showing Answers 1 - 2 of 2 Answers

rrl

  • Oct 22nd, 2005
 

Well. I found the answer myself. I am putting it here for the benefit of others.

State - districts is a 1-many relation (bi-directional relation).

here In Oops it becomes has a relations. So we have to design a state class which will contain a collection of ditricts as one of the attributes.

This is a bi-directional relation. So we have to design a distric class where a state class is denoted by means of an attribute.

State class will have getDistricts, setDistricts, addDistrict, deleteDistrict methods

District class will have getState, setState method

  Was this answer useful?  Yes

Nitin Gupta

  • Jan 3rd, 2006
 

Alternatively, what can also be done is create a connection class

class connection {

Vector leftNodes;

Vector rightNodes;

}

here leftNode will contain a state and rightNode will contain multiple districts. THis design support many-to-Many, oneto-one and many-to-one and one to many relationships

  Was this answer useful?  Yes

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

 

Related Answered Questions

 

Related Open Questions