Re: Circular dependency

Discussion in 'Java' started by Andrew Cowper, Aug 20, 2003.

  1. (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.
    Andrew Cowper, Aug 20, 2003
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Roedy Green

    Re: Circular dependency

    Roedy Green, Aug 19, 2003, in forum: Java
    Replies:
    0
    Views:
    394
    Roedy Green
    Aug 19, 2003
  2. John Hodgson

    Re: Circular dependency

    John Hodgson, Aug 20, 2003, in forum: Java
    Replies:
    0
    Views:
    410
    John Hodgson
    Aug 20, 2003
  3. John C. Bollinger

    Re: Circular dependency

    John C. Bollinger, Aug 20, 2003, in forum: Java
    Replies:
    0
    Views:
    396
    John C. Bollinger
    Aug 20, 2003
  4. DinkyToy

    circular dependency between jars

    DinkyToy, Apr 7, 2005, in forum: Java
    Replies:
    0
    Views:
    401
    DinkyToy
    Apr 7, 2005
  5. Kiuhnm
    Replies:
    16
    Views:
    741
    Jonathan Mcdougall
    Jan 3, 2005
Loading...

Share This Page