Originally posted by eric moon:
I have a utility that reads and writes objects to disk. I have an object Params that gets stored to disk via the utility. Params is a singleton that gets created when the user first starts the program, and initializes the users data. So in the private constructor to Params, I first check whether the file exists on disk, and if it does, I want to use it to create my Params object. I though maybe I could just use "this", but the compiler is complaining. How best to do this?
As you found out you can't assign a new object to "this". Since you are already using a factory method for the singleton
pattern, why not put the creation detail, i.e. the choice between deserializing from disk, or creation from scratch, in that factory?
HTH
- Peter