How to phrase questions about spotting design issues in programs I like to give my students questions asking them to find and correct design issues in code. As an example, I gave them the following question:

/**
    This class represents the user-system of the application. 
    There must be only one object of this class. 
 */
public class UserSystem {
   private Map&lt;String,String&gt; users;// maps user to password

   public UserSystem() {
     users = new HashMap&lt;String, String&gt;();
   }

   public void addUser(String username, String password) {
     users.put(username,password);
   }

   public Boolean isAuthorized(String username, String password) {
     if (!users.containsKey(username))
        return false;
     return users.get(username).equals(password);
   }
}


The question text was something like: 


  "The class compiles correctly but has a design problem. What is the design problem? Write a main program that demonstrates it. Use one of the design patterns we used in class to rewrite the class such that the problem is fixed. What design pattern did you use?"


The answer I aimed for was that, since the constructor is public, users of this class might create multiple objects of the class. The solution should be to convert this class into a singleton by making its constructor private (and adding a static member variable INSTANCE). 

Indeed, some students got this correctly, but other students answered with all sorts of other design bugs, such as:


The method "addUser" does not check whether the username already exists.
The method "addUser" might be used by unauthorized users to enter their name into the system.
The methods are not synchronized.


etc...

It is true that these issues can be problematic in some cases, however, this depends on the context and the usage of the class. I wanted them to focus on a specific issue which I deliberately wrote in the Javadoc to this class. However, many students probably did not notice this.

MY QUESTION IS: in the future, how can I phrase such questions such that the answers will be more focused?
It is true that these issues can be problematic in some cases, however, this depends on the context and the usage of the class.


The "design problem" that you were hoping they would find also depends on the context and usage of the class. We have no idea whether the users of this class are obeying your JavaDoc. In fact, I could see an argument that your "design problem" is invalid because anybody who violates the JavaDoc is going outside the bounds of your design in the first place! Compare that to the functions with no JavaDoc, and honestly I'm more convinced by your students' answers than I am of your intended answer.

Asking "what is wrong with the design of this class" is too broad. You need to provide more context: perhaps provide the UserSystem class and then another class that uses it incorrectly (by creating a new UserSystem instance for every user, for example), and then ask what the design problem is in that code and how it could be prevented in the future.

If you want a specific answer, you need to ask a specific question. All of the answers your students provided sound perfectly reasonable to me.