This
thread is really old,
But anyway, I just post my thoughts here, I have been reading Max's book for
a while, then recently I bought Book by Andrew and Terry. The 2nd edition is better in terms of mocking the real-world exam.
Regarding the LockManager, and DataFileAccess (database) classes that
are part of the Data class ( I prefer to refer this pattern as composition),
in Andrew's book, both are declared as static member within dataclass (DvdFileAccess and ReservationManager are static members), therefore,
for all instance of Data class, it is gauranteed to have only one instance of LockManager and DataFileAccess created when Data class is loaded, this is simple and straightforward.
But If I use Singleton pattern for FileAccess, one question I have is how to pass the database file path into the DataFileAccess class if it is a singleton? Do I have to pass the path when I call DataFileAccess.createInstance()?
When is the circumstance that I use a instance of Singleton over a class scoped static member ? I guess, If some one load the class twice, there will be two instances of DataFileAccess, but not the case in Singleton.
Thanks, Ziji