View Single Post
  #4   Spotlight this post!  
Unread 10-03-2014, 01:30
MatthewC529 MatthewC529 is offline
Lcom/mattc/halp;
AKA: Matthew
FRC #1554 (Oceanside Sailors)
Team Role: Mentor
 
Join Date: Feb 2014
Rookie Year: 2013
Location: New York
Posts: 39
MatthewC529 is on a distinguished road
Re: Is getWatchdog() required in RobotTemplate.java?

I personally use Watchdog.getInstance() in my code.

Watchdog scruffy = Watchdog.getInstance(); //for instance

getInstance() is a common method provided in Singleton classes or classes that are mean to NOT be instantiated. A good example is the Math class in Java SE 7 (Does not have getInstance()... meaning "REALLY do not get this instance"). Another example is the Java SE 7 Toolkit class which some games use for getting the screen width of your computer. It has a method called Toolkit.getDefaultToolkit() which might as well be Toolkit.getInstance().

That method ensures only ONE instance of the class EVER exists. You wouldnt want two logging classes posting to the console (in most cases) so you make it a singleton with getInstance() capability. Only one Watchdog will EVER exist. That is all that means.

You can freely use getInstance to have your own reference to the Watchdog object just so you are familiar. Like mine is named Scruffy.
Reply With Quote