Results 1 to 2 of 2

Thread: Persisting singletons with state

  1. #1
    Join Date
    Feb 2007
    Location
    Huntington Beach, CA
    Posts
    26

    Question Persisting singletons with state

    I'm looking for an architecture best practice for persisting singletons with state. I'm sure this comes up often enough, and maybe I'm just too tired to see the obvious solution. An example:

    I have a class CCB (change control board, for those not working within bureaucracies):

    Code:
    public class CCB {
        private User chair;
        private Set<User> voters;
    	
        // getters & setters
    }
    This should be a singleton, as there is only one CCB. An application admin should be able to change the content of voters through a web interface, and have those changes persisted to a database (I'm using Hibernate).

    The solutions that come to mind seem inelegant or restrictive to me. If I didn't need to allow users to modify state, I could create a Spring bean, with a property editor for User, and put it all in an appContext.xml. But that's not an option. I could also give CCB an id property, and hard code that id into the CCB DAO (or put the id into the appContext.xml and inject it into a CCB service bean). Again, seems a little heavy handed.

    How is this normally implemented?

    Thanks in advance,
    Philip

  2. #2
    Join Date
    Sep 2006
    Location
    UK
    Posts
    8,424

    Default

    I'm not quite sure what the problem is here. If you want only one of them, then create and initial one in the database and don't allow a new one to be created in the code.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •