View Single Post
Old Apr 2nd, 2008, 10:17 AM   #2
Jimbo
Battle Programmer
 
Jimbo's Avatar
 
Join Date: Feb 2006
Location: Bellevue, WA, USA
Posts: 754
Rep Power: 3 Jimbo is on a distinguished road
Re: How to return to an instance?

You'll want a slightly different design where you keep a SandHopper object and instead of creating a new one each time you set it visible again. You can wrap this into a static method similar to this:

class SandHopper {
  private static SandHopper onlySandHopper;
  public static SandHopper GetSandHopper() {
    if(onlySandHopper == null) {
      onlySandHopper = new SandHopper();
    }
    return onlySandHopper;
  }

  // .. the rest of your class...
}
With this, you might want to make your constructors private, so that only GetSandHopper() can create one. The benefit to this: you reuse the same one all the time. The drawback: you can only have 1 SandHopper (if you want more than one, you can leave the constructors public, but anybody who calls GetSandHopper() will always use the same one).
__________________
<insert disclaimer here>
<insert shameless plug for Visual Studio here>
Jimbo is offline   Reply With Quote