Broheim
Diamond Member
- Feb 17, 2011
- 4,587
- 3
- 81
I actually wanted to make the whole Deck static as I only want there to be 1 deck during the entire execution. But when I declared the class static it gave me problems. I might be able to fix it though.
singleton pattern is what you are looking for.
Code:
class Dao
{
private static Dao _dao;
private Dao()
{
}
public static Dao GetInstance()
{
if (_dao != null) return _dao;
_dao = new Dao();
return _dao;
}
}
this is a straight copypasta from a project I'm working on (Data access object class), and this ensures that you will ever only have one instance of that class. it's probably the most basic design pattern out there, but I've found it to be the one I use the most.
