Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

What design pattern is this ...

 
Dave Teare
Ranch Hand
Posts: 80
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,
In my DBConnectionManager I want to ensure that only one implementation exists per db.db file. In other words, I see no reason to prevent multiple databases from running within the same JVM, as long as each one has a unique Data and LockManager instance.
To ensure this, I have made the constructors private, and provided a static factory method that checks to see if a Data/LockManager already exists for this filename, and only creates new instances if it does not already exist.
What design pattern did I use here? I thought at first it was a Singleton pattern, but in reality I have more than one instance of the classes.
Please advise.
--Dave.
 
Mark Spritzler
ranger
Sheriff
Posts: 17278
6
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That is the singleton pattern.
You don't really need to have this pattern in your assignemtn. Don't worry about multiple Data classes in a JVM, that isn't in the requirements, so adding it won't get you bonus points.
All you really have to do is create one instance in your ConnectionFactory, and pass the reference to each Connection object as they get created.
Good Luck.
On another subject I just submitted my Beta assignment. Since it worked for you, I thought it will probably work for the assessor. I hope.
If not I'll just fail, not a biggie. I mean of course I like passing and getting high marks, but if not I can keep in sight that the main purpose here is to help Sun test their new assignment.
Mark
 
Dave Teare
Ranch Hand
Posts: 80
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Good luck Mark, I hope it works for them! I had to pay money for my test, so I am being less aggressive I hope you get it working before the real assignment comes out.
As for the Singleton pattern, I already wrote the code, so I think I'll keep it. Besides, I am too anal to allow developers using my code to hang themselves. I know, as if anyone is going to use my assignment!
--Dave.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic