Blog Stats
  • Posts - 25
  • Articles - 0
  • Comments - 10
  • Trackbacks - 36

 

Thursday, December 30, 2004

Is the Singleton Question such a difficult one to answer

I do a lot of interviewing in my role, and one of the first questions I ask when interviewing a candidate is

What is a Singleton?

Most candidates get it right, A class where only a single instance can be created, if the candidate does not get the right answer, I explain what it is, as not eveyone is a pattern geek, even though this is one of the most common and well known patterns.

What I ask next, is to provide a minimal implementation, in the language of choice ( most cases its one of the following, Java, C# or C++ ), now this is where it starts to get interesting.  The following is an example of one recent candidates answer, they wrote this on the board with a straight face

class Singleton {

public int count;

}

This caused much discussion between the candidate and myself, obviously they did not understand anything about the C# language at all, and the concept of a private constructor was completly foreign, I then had some fun for the rest of the interview watching the candidates facial expressions as I asked more simple questions, about his implementation.

FYI

Nice Solution to the Singleton question using C#

 

 

Copyright © David Lattimore-Gay