Re: instanciate an interface - alternatives?
From: Andrew Hobbs (andrewh1_NoSpam__at_iinet.net.au)
Date: 01/29/04
- Next message: Adi Schwarz: "Re: instanciate an interface - alternatives?"
- Previous message: Glen Able: "Class variable initializers"
- In reply to: Adi Schwarz: "instanciate an interface - alternatives?"
- Next in thread: Ashton: "Re: instanciate an interface - alternatives?"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Thu, 29 Jan 2004 22:56:17 +0800
"Adi Schwarz" <adolf.schwarz.news.01-04@gmx.at> wrote in message
news:bvb3gh$q833n$1@ID-212825.news.uni-berlin.de...
> 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);
> }
It is not a matter of workarounds. You do not seem to understand how and
why interfaces are used. I would suggest going back to your text book (and
if you do not have one then access 'Thinking in Java' by Bruce Eckel which
is available online).
Andrew
--
********************************************************
Andrew Hobbs PhD
MetaSense Pty Ltd - www.metasense.com.au
12 Ashover Grove
Carine W.A.
Australia 6020
61 8 9246 2026
metasens AntiSpam @iinet dot net dot au
*********************************************************
>
> 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: Adi Schwarz: "Re: instanciate an interface - alternatives?"
- Previous message: Glen Able: "Class variable initializers"
- In reply to: Adi Schwarz: "instanciate an interface - alternatives?"
- Next in thread: Ashton: "Re: instanciate an interface - alternatives?"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|