Mini Assignment #2

Arthur Dick
October 28, 2004
Assignment Specifications

The Question:

You have been contracted out by a small software company, Mikeroesoft, to assist with the integration of new functionality into an existing piece of software. The code below is a small part of the system currently in place. It is responsible for starting an action, which is simply a function contained elsewhere in the same class.

public void doAction(String command) {
   if (command.equals("start") {
      start();
   }
   else if (command.equals("stop")) {
      stop();
   }
   else if (command.equals("another")) {
     another();
   }
}

In the next release, Mikeroesoft plans to add approximately 100 new actions to the existing system, with the possibility of even more being added at a later date.

Discuss, using concepts covered in class, what changes you would recommend to Mikeroesoft to accommodate for the large number of proposed new actions, and why you believe these changes would be beneficial.

Blooms Taxonomy

This question relates to the upper three levels of blooms taxonomy because the student will have to analyse the situation, and synthesize a suitable solution. There are many different suggestions which could be made, and there is no wrong answer, as long as the student defends his position. I, however, will only discuss reflection for my solution.

The student is also asked to justify why their design would be better than some other possible solutions. This requires that the student is able to evaluate his own design.

Therefore, this question tests all of the upper three levels of blooms taxonomy.

Solution

One solution which I believe would deserve an A for this question would be:

Analysis:
The existing system requires going through a large chain of if-else statements testing to find the name of the action to be called. If this system were to be expanded as is, it would require the maintenance of an ever-increasing number of if statements.

Synthesis:
I would suggest that Mikeroesoft change the doAction() function to automatically call the function associated with a particular command using reflection.

Evaluation:
By using reflection, the need to maintain an enormous chain of if statements is eliminated, because it has been replaced by the reflective call, which determines automatically which action should be executed.

Also, if any new actions are going to be required in the future, simply adding a new function to the class will add the new functionality.

This design should reduce the time it takes to add the new actions, and will eliminate the possibility of errors being made within the if-else chain, as it is no longer required.

Take me back.