instanciate an interface - alternatives?
From: Adi Schwarz (adolf.schwarz.news.01-04_at_gmx.at)
Date: 01/29/04
- Next message: Thomas Fritsch: "Re: Dang! On-Line Compiler is broke!"
- Previous message: ak: "Re: How to change JFileChooser text elements?"
- Next in thread: BarryNL: "Re: instanciate an interface - alternatives?"
- Reply: BarryNL: "Re: instanciate an interface - alternatives?"
- Reply: Andrew Hobbs: "Re: instanciate an interface - alternatives?"
- Reply: Ashton: "Re: instanciate an interface - alternatives?"
- Reply: Tor Iver Wilhelmsen: "Re: instanciate an interface - alternatives?"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Thu, 29 Jan 2004 14:57:59 +0100
Hi,
I know that it is not possible to instanciate an interface. But are
there any workarounds?
I want to write a class that stores and manages certain objects. This
objects have to implement an interface called "SelfLoadable", that means
they can manage to load their information (from a file, database,
internet,...) themselves by providing a key that identifies the object
(e.g. primary key).
public interface SelfLoadable {
public abstract void load(Object key);
}
Now my main class named ObjectCache shall contain a method named "get".
It shall look up if this object is stored in the cache, if not it shall
create it and automatically load its data:
private Hashtable cache = new Hashtable();
public SelfLoadable get(Object key) {
SelfLoadable o;
o = (SelfLoadable)cache.get(key);
if (o == null) { //Object not stored?
o = new SelfLoadable();
o.load(key);
}
return o;
}
new SelfLoadable(); does not work since it is an interface. But how do I
create the object if it is not stored in cache?
The idea is that I do not have to care about the cache - the get method
shall always return the object I request, no matter if the object is
cached or not.
I hope I could reduce the problem so far that it is understandable.
greets,
-adi
- Next message: Thomas Fritsch: "Re: Dang! On-Line Compiler is broke!"
- Previous message: ak: "Re: How to change JFileChooser text elements?"
- Next in thread: BarryNL: "Re: instanciate an interface - alternatives?"
- Reply: BarryNL: "Re: instanciate an interface - alternatives?"
- Reply: Andrew Hobbs: "Re: instanciate an interface - alternatives?"
- Reply: Ashton: "Re: instanciate an interface - alternatives?"
- Reply: Tor Iver Wilhelmsen: "Re: instanciate an interface - alternatives?"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|
|