Greetings, In OOP, we often talk about "Encapsulation". It's a very good stuff. Agree?
As a programmer, I apply the same concept in programming as well. As far as I know, "interface" provides 2 features to me. 1. define a set of methods for the concrete class to implement. 2. define a set of constants for sharing among the implemented classes Refer to the original question from Jason Kilgrow...asked: "Which interface's method have I implemented? Does it matter?" Well the answer is...you implemented both interfaces, Car & Boat. Regardless the OO design of those classes are good or not. From the caller point of view, the concrete class "Amphibious" is a Car when it's casted as a Car OR is a Boat if it's casted as a Boat. e.g. provided by Martha Fourt Car aCar = (Car) (new Amphibious()); Boat aBoat = (Boat) (new Amphibious()); aCar.drive(); aBoat.drive(); That's fine. The JVM has done when the specification has stated. Well, I treat this as a kind of "Encapsulation". -Victor >From : "Leah Chuckran" <[EMAIL PROTECTED]> on 03/06/2002 01:13:55 PM To: [EMAIL PROTECTED] cc: (bcc: Victor HT CHEUNG/HD/HKSARG) Subject: [jdjlist] Re: Same Method, Multiple Interfaces -----Original Message----- From: Brandon Rife [mailto:[EMAIL PROTECTED]] Sent: Monday, May 27, 2002 8:21 AM To: JDJList Subject: [jdjlist] Re: Same Method, Multiple Interfaces Java does not allow multiple inheritance, therefore there never be two competing implementations of a given method signature from multiple interface. There is nothing to resolve. -----Original Message----- From: H Shankaranarayanan [mailto:[EMAIL PROTECTED]] Sent: Monday, May 27, 2002 12:00 AM To: JDJList Subject: [jdjlist] Re: Same Method, Multiple Interfaces 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 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 ----------------------------- Disclaimer: This email (including every file transmitted with it) may contain confidential and privileged information and is solely for the use of the intended recipient(s). Any unauthorised dissemination, distribution or copying of this email is strictly prohibited. Please notify the sender and delete this email immediately if you have received this by mistake. We do not accept liability arising from email transmitted by mistake. To change your membership options, refer to: http://www.sys-con.com/java/list.cfm
