Article View: borland.public.jbuilder.java.language
Article #8094Re: Code for a Factory Singleton class?
From: Michael Rachow
Date: Wed, 25 Apr 2001 07:33
Date: Wed, 25 Apr 2001 07:33
55 lines
2394 bytes
2394 bytes
Hi Andrew, "Andrew Shrosbree" <A.Shrosbree@ballarat.edu.au> schrieb im Newsbeitrag news:3AE67517.5B43766@ballarat.edu.au... > Greetings > > I have an application which uses 4 separate factories. Each factory is a > singleton which maintains a hashtable of classes. I can ask each factory to > return a particular instantiated class by calling (for example) > > jMyObject oObject = jFactory1.getObjectFor( "ClassName" ); > > As you can see, my getObjectFor method is static. In fact all the methods in my > factory classes are static. If you would have used the naming convention that class names have to start with an uppercase letter we could have seen. > Now all the factories work exactly the same, so I want to subclass them all from > a neat base-factory class. But of course, I can't do this because the Instance > method in each of my classes returns a different type. > > I have grappled with Rod Waldhoff's article 'Implementing the Singleton Pattern > in Java' and cannot make head of tail of how to solve my subclassing problem. > > Does anybody have some real code which demonstrates a solution to this (common) > problem? You can make your methods return type an Object and cast the returned reference to the just desired type. Greetings Michael > > -- > Andrew N. Shrosbree > Project Manager and Technical Architect > Collaborative Centre for eHealth > University of Ballarat > Victoria, Australia > Tel: +61 (0)3 5327 9896 > Fax: +61 (0)3 5327 9307 > Mob: +61 (0)415 645 291 > >
Technical Details
Message-ID:
<3ae68133_1@dnews>Path:
arc1-ca.pugleaf.net!newsfeed.google.com!sn-xit-03!supernews.com!logbridge.uoregon.edu!news.maxwell.syr.edu!newsfeed.wirehub.nl!PeerFeed.KWeb.on.ca!dnewsReferences:
<3AE67517.5B43766@ballarat.edu.au>Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: f74b3,6e3c99b0815d7bc4 X-Google-Attributes: gidf74b3,public X-Google-ArrivalTime: 2001-04-25 00:52:03 PST From: "Michael Rachow" <mrachow@BeraCom.de> Newsgroups: borland.public.jbuilder.java.language References: <3AE67517.5B43766@ballarat.edu.au> Subject: Re: Code for a Factory Singleton class? Date: Wed, 25 Apr 2001 09:33:22 +0200 Lines: 57 X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 5.50.4133.2400 X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4133.2400 NNTP-Posting-Host: 217.80.7.22 Message-ID: <3ae68133_1@dnews> X-Trace: dnews 988184883 217.80.7.22 (25 Apr 2001 00:48:03 -0700) Path: arc1-ca.pugleaf.net!newsfeed.google.com!sn-xit-03!supernews.com!logbridge.uoregon.edu!news.maxwell.syr.edu!newsfeed.wirehub.nl!PeerFeed.KWeb.on.ca!dnews