Article View: borland.public.jbuilder.java.language
Article #17505Re: Dynamic method binding
From: Steve Schafer (TeamB)
Date: Thu, 05 Nov 1998 00:00
Date: Thu, 05 Nov 1998 00:00
53 lines
1808 bytes
1808 bytes
On 5 Nov 1998 14:28:44 GMT, "Vishal P Mahabeer" <vishalm@spl.co.za>
wrote:
>I want this to be a place holder for an object that can be one of
>several classes.
You have to make use of inheritance and polymorphism here. Declare a
"base" class (possibly abstract) and give it a setController method.
public abstract class MyBase {
public abstract void setController();
}
Alternatively, declare an interface that has a setController method.
public interface MyInterface {
public void setController();
}
Now, each of your classes that has a setController method should
either extend MyBase or implement MyInterface:
public class MyClass extends MyBase {
public void setController() {
// stuff goes here
}
}
or
public class MyClass implements MyInterface {
public void setController() {
// stuff goes here
}
}
Finally, your addToDict method should be declared like this:
public void addToDict(String key, MyBase value) ...
or
public void addToDict(String key, MyInterface value) ...
The bottom line is that you have to let the compiler know that value
represents an object instance that does indeed have a setController
method.
-Steve
Technical Details
Message-ID:
<364fd49f.36318590@forums.borland.com>Path:
arc1-ca.pugleaf.net!unknown!not-for-mailReferences:
<01be08c8$d3d2edd0$c60924c4@vishalm>Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: f74b3,db2d30fe5814e4cb X-Google-Attributes: gidf74b3,public From: pandeng@telepath.com (Steve Schafer (TeamB)) Subject: Re: Dynamic method binding Date: 1998/11/05 Message-ID: <364fd49f.36318590@forums.borland.com> X-Deja-AN: 408709481 Content-Transfer-Encoding: 7bit References: <01be08c8$d3d2edd0$c60924c4@vishalm> Content-Type: text/plain; charset=us-ascii Organization: TeamB Mime-Version: 1.0 Reply-To: pandeng@telepath.com Newsgroups: borland.public.jbuilder.java.language