Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > Re: Circular dependency

Reply
Thread Tools

Re: Circular dependency

 
 
Andrew Cowper
Guest
Posts: n/a
 
      08-20-2003
http://www.velocityreviews.com/forums/(E-Mail Removed) (Brian J. Sayatovic) writes:

> public class State {
> public static final State INITIAL_STATE = loadState(0);
> protected static State loadState(int value) {
> Persistence persistence = Persistence.getDefaultInstance();
> return persistence.getState(0);
> }
> }
>
> public class Persistence {
> public static Persistence getDefaultInstance() {
> // ... *standard* singleton pattern
> }
> public State getState(int value) {
> // ... SELECT * FROM STATES WHERE STATE_VALUE=?
> }
> }
>
> I'm drawing a blank. How can I design around this?


How about this - puts off the initialisation of the static member until
it is actually needed - and calling getState on the Persistence class
won't try and do it.

public class State {

private static final State INITIAL_STATE;

public static State getInitialState() {
if (INITIAL_STATE == null) {
INITIAL_STATE = loadState(0);
}
return INITIAL_STATE;
}

protected static State loadState(int value) {
Persistence persistence = Persistence.getDefaultInstance();
return persistence.getState(0);
}
}

CheersAndrewC.

--
Pick a different user name to email me.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
circular dependency between jars DinkyToy Java 0 04-07-2005 02:12 PM
Semi-circular definitions (plus circular references) Kiuhnm C++ 16 01-03-2005 03:49 AM
Re: Circular dependency John C. Bollinger Java 0 08-20-2003 02:22 PM
Re: Circular dependency John Hodgson Java 0 08-20-2003 01:22 PM
Re: Circular dependency Roedy Green Java 0 08-19-2003 07:49 PM



Advertisments