Re: Separate interface and implemenation problem..
////// 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);
Right. There is no reason to believe that a TreeNode
has an addChild() method; the only methods you can be sure
a TreeNode has are setParent() and the things inherited
from Object. Possible remedies:
- Include an addChild() method in the TreeNode
interface definition.
It would be nice if Java allowed protected (or private) modifiers
inside an interface [why doesn't it?]
- Use `((TreeNodeImpl)parentNode).addChild(this)', and
pray that you're never called with some other kind
of TreeNode.
Had thought of this, but I like static type-checking. I would sooner
drop the idea of using an interface [for the reasons I'm using them
here] than implement this.
}
private void addChild(TreeNode childNode) { ... }
}
////// Factory.java //////
public class Factory
{
public static TreeNode createTreeNode()
{
return TreeNodeImpl();
I guess you mean `new TreeNodeImpl()'.
Ha, yes. I always forget to type that operator. Why is it even in the
language; when is the class constructor ever referenced, except after
new?
}
}
--
Eric.Sos...@sun.com- Hide quoted text -
I figured it was a long shot. Thank you for the response Eric,
Kind regards,
Eliott