I am trying to implement some hierachy, say, one cell contains an array of attributes. 'cell' and 'attribute' are both classes.
The problem is I want to be able to access the other party from both sides, i.e., access 'attribute' from 'cell' (which is straightforward) and the other way around (which I don't know whether it's possible).
The 1st question is, do I need to implement something like 'pointer' in the lower class (in this case, 'attribute') to the class in which (an array of)it is contained, or is there any backward infrastructure already existing in Java that I can make use of?
The 2nd question is, if I shall have to implement this 'pointer'-like-thing, is there some type other than reference that I could use? Because if this element should be one reference, it looks like the 'attribute' also contains one 'cell', which is not at all logical.
I just began programming with Java. Please give some hints! Thanks a lot!
One solution would be to pass the Cell to the Attibute as an attribute of a method such as Attribute.setCell(Cell c). Given that only a pointer is passed then the overhead shouldn't be too high. There may be problems though, for instance, if a single Attribute were shared by several Cells.
Having done that though, you now have two classes that are very closely coupled. You may benefit from looking at refactoring the classes and extracting the common functionality into another class.