Separate interface and implemenation problem..



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();
}
}
.



Relevant Pages

  • Re: Another Code Sample for Crituque
    ... > believe represents bad programming technique. ... The listing below is from a sample of Java code written for the Java ... an interface, and an implementation. ... public void close; ...
    (comp.lang.cpp)
  • Re: Design question - methods calling methods
    ... time I've spent writing Java - I started in 1997 but had a 4 year gap ... A class can implement an interface - that is, it is a subtype of the ... public void fooishBehavior; ... public class FooImpl implements Foo ...
    (comp.lang.java.programmer)
  • Re: IEnumerator/IEnumurable
    ... the generic form *must* still offer the untyped form. ... and an interface I requires a particular method ... public void Add ... certainly *wasn't* in Java until Java 1.5, ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Separate interface and implemenation problem..
    ... deep in a thread titled "Decouple Javadoc from Java". ... interface type so it does not have access.. ... public void setParent; ... class TreeNodeImpl implements TreeNode ...
    (comp.lang.java.programmer)
  • Re: Separate interface and implemenation problem..
    ... MRe wrote: public interface TreeNode ... public void setParent; ... You can access a class' private elements only from the ...
    (comp.lang.java.programmer)