Separate interface and implemenation problem..
- From: MRe <pgdown@xxxxxxxxx>
- Date: Thu, 4 Jun 2009 07:20:46 -0700 (PDT)
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();
}
}
.
- Follow-Ups:
- Re: Separate interface and implemenation problem..
- From: Roedy Green
- Re: Separate interface and implemenation problem..
- From: Eric Sosman
- Re: Separate interface and implemenation problem..
- Prev by Date: Re: Maven example
- Next by Date: Re: In which circumstances a Class.forName() can fail?
- Previous by thread: In which circumstances a Class.forName() can fail?
- Next by thread: Re: Separate interface and implemenation problem..
- Index(es):
Relevant Pages
|