M
MRe
Hi,
I had posted this question already to comp.lang.java.help nested
deep in a thread titled "Decouple Javadoc from Java". I am re-posting
here to give it more visibility.
I am separating interface from implementation (example below) and
have hit on a problem..
The problem is that I need to access private members of the class
I'm in, but through a different object (and this object is of the
interface type (not the implementation) so it does not have access..
the example is probably better able to explain it.
I know this is a bit of a hack (for the reason I'm using it, abusing
the type-system to get a feature Java doesn't provide) but I'm sure
someone must have encountered such a problem and found an eloquent
solution?
Thank you for any help,
Kind regards,
Eliott
~~~
////// TreeNode.java //////
public interface TreeNode
{
public void setParent(TreeNode parentNode);
}
////// TreeNodeImpl.java //////
class TreeNodeImpl implements TreeNode
{
public void setParent(TreeNode parentNode)
{
// problem here: cannot find symbol addChild(TreeNodeImpl)
parentNode.addChild(this);
}
private void addChild(TreeNode childNode) { ... }
}
////// Factory.java //////
public class Factory
{
public static TreeNode createTreeNode()
{
return TreeNodeImpl();
}
}
I had posted this question already to comp.lang.java.help nested
deep in a thread titled "Decouple Javadoc from Java". I am re-posting
here to give it more visibility.
I am separating interface from implementation (example below) and
have hit on a problem..
The problem is that I need to access private members of the class
I'm in, but through a different object (and this object is of the
interface type (not the implementation) so it does not have access..
the example is probably better able to explain it.
I know this is a bit of a hack (for the reason I'm using it, abusing
the type-system to get a feature Java doesn't provide) but I'm sure
someone must have encountered such a problem and found an eloquent
solution?
Thank you for any help,
Kind regards,
Eliott
~~~
////// TreeNode.java //////
public interface TreeNode
{
public void setParent(TreeNode parentNode);
}
////// TreeNodeImpl.java //////
class TreeNodeImpl implements TreeNode
{
public void setParent(TreeNode parentNode)
{
// problem here: cannot find symbol addChild(TreeNodeImpl)
parentNode.addChild(this);
}
private void addChild(TreeNode childNode) { ... }
}
////// Factory.java //////
public class Factory
{
public static TreeNode createTreeNode()
{
return TreeNodeImpl();
}
}