On 28 Aug 2005, at 20:00, Dennis Byrne wrote:
1) Removing methods from a super interface doesn't keep youfrom adding
similar methods to subclasses
Are you saying people using the methods you want to remove in
TreeNode would have to then subclass it?
TreeNode is, and always has been, an interface. So, of course, yes.
implementation); in the supplied patch, the methods arestill in the
class TreeNodeBase.
... and what happens to people doing this?
TreeNode basicTeeNode = new TreeNodeBase();
TreeNode customTreeNode = new CustomTreeNodeBase();
list.add(treeNode);
list.add(treeNode2);
for(i = list.iterator(); i.hasNext();){
TreeNode anyTreeNode = (TreeNode)i.next();
anyTreeNode.methodYouRemoved();
}
As I said, anyTreeNode has static type TreeNode. Calling a method that is removed from the interface on a variable with static type TreeNode obviously would be a problem, but as far as I can see, nobody would have written such code.
In your case, I suppose CustomTreeNodeBase would extend TreeNodeBase, and anyTreeNode could have static type TreeNodeBase in the loop.
2) Removing methods from an interface only influences placeswhere
those methods are called on a variable that has theinterface as it's
static type.
Java 101: interfaces can't have static methods.
Dennis Byrne
OO 101: a static type is the type of a variable as it is declared in the source code, and is what we work with at compile time. The dynamic type is the actual type of the object the variable refers to at a given time at runtime, through polymorphism the dynamic type at a given time at runtime has to be a subtype of the static type.
What do static methods have to do with all this?
<x-tad-smaller>Met vriendelijke groeten,
Jan Dockx
</x-tad-smaller><x-tad-smaller>
PeopleWare NV - Head Office</x-tad-smaller><x-tad-smaller>
Cdt.Weynsstraat 85
B-2660 Hoboken
Tel: +32 3 448.33.38
Fax: +32 3 448.32.66 </x-tad-smaller><x-tad-bigger>
</x-tad-bigger><x-tad-smaller>
PeopleWare NV - Branch Office Geel</x-tad-smaller><x-tad-smaller>
Kleinhoefstraat 5
B-2440 Geel
Tel: +32 14 57.00.90
Fax: +32 14 58.13.25</x-tad-smaller><x-tad-bigger>
</x-tad-bigger><x-tad-smaller>
http://www.peopleware.be/
</x-tad-smaller><x-tad-smaller>http://www.mobileware.be/</x-tad-smaller>
smime.p7s
Description: S/MIME cryptographic signature

