All this is fine but cud anyone let the group know
how the JVM decides which interface method to implement.
Cos both cannot be implemented here. If yes then a name clash
arises. So hows this resolved by the JVM?

--Shankar

-----Original Message-----
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]]
Sent: Saturday, May 25, 2002 6:41 PM
To: JDJList
Subject: [jdjlist] Re: Same Method, Multiple Interfaces


dear tomm, if you had read my posting you could've
spared yourself the work ;o)
greets

> It doesn't, afaik, matter to Java.  But it shows a shortcoming in your 
> OO design.  Your ambiguity comes because you have two "things", a car 
> and a boat, that are conceptually related but you don't relate them in 
> the design.  A better design (though still not necessarily the best) 
> would be to have a base interface, say Vehicle, that has the drive 
> method and the two sub interfaces, Car and Boat, both of which extend 
> it.  Then you could create an amphibious car without trying to make it 
> into a boat.
> 
> As a general rule, whenever you find yourself with two or more classes 
> or interfaces that have an area of commonality, or "overlap", place the 
> common features into a super class or interface, whichever is 
> appropriate, and remove them from the separate classes or interfaces. 
>  This will solve most, if not all, problems with ambiguity.
> 
> public interface Vehicle {
>     // Define actions/characteristics common to all vehicles
>     public void drive();
> }
> public interface Car extends Vehicle {
>     // Define actions/characteristics unique to cars
> }
> public interface Boat extends Vehicle {
>     // Define actions/characteristics unique to boats
> }
> public class Amphibious implements Car {
>     public void Drive() {
>         ...
>     }
> }
> 
> 
> Tomm
> 
> 
> 
> To change your membership options, refer to:
> http://www.sys-con.com/java/list.cfm
> 

-- 
GMX - Die Kommunikationsplattform im Internet.
http://www.gmx.net


To change your membership options, refer to:
http://www.sys-con.com/java/list.cfm


To change your membership options, refer to:
http://www.sys-con.com/java/list.cfm

Reply via email to