Re: instanciate an interface - alternatives?

From: Andrew Hobbs (andrewh1_NoSpam__at_iinet.net.au)
Date: 01/29/04


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
>


Relevant Pages

  • Re: kobj multiple inheritance
    ... The kobj lookup scheme doesn't require any kind of locked memory ... >> This proposed scheme also traverses through base classes of base classes ... >> Interface lookup using current kobj can be done expliticly. ... The cache is large even ...
    (freebsd-arch)
  • Cisco 7204VXR Interface ignored packet
    ... see the configuration not just the show diag & interface info. ... 509K bytes of non-volatile configuration memory. ... 256 max cache size, 256 in cache ... 22496866 hits in cache, 0 misses in cache ...
    (comp.dcom.sys.cisco)
  • Re: [PATCH 08/28] SECURITY: Allow kernel services to override LSM settings for task actions [try #2]
    ... interface, at the granularity you want to support distinctions to be made. ... context and begin caching". ... Do any of the interfaces allow a task to act on a cache other than one ...
    (Linux-Kernel)
  • Generics mit "Zirkulärer Typreferenz"
    ... generischen Cache speichern. ... Interface implementieren: ... internal interface ICacheablewhere T: ... Über den Key wird das Objekt identifiziert, ...
    (microsoft.public.de.german.entwickler.dotnet.csharp)