Friday, May 15, 2015

Mark IV Special Coffee Maker API implementation

In his book "UML for Java Programmers", Robert C. Martin (from Object Mentor) explains an object oriented software design problem: Writing an implementation of the software for the fictional Mark IV Special Coffee Maker. The solution must use the low-level API of the hardware that controls the different parts of the machine, which is provided as the CoffeeMakerAPI Java interface. Robert also published the complete Mark IV Special Coffee Maker chapter for us.

I am not here to give another solution for the problem. Instead, I wrote the CoffeeMakerGUI application, that contains a CoffeeMakerAPI implementation that lets you to manually test your solution by using a simulated Coffee Maker machine:


To compile it using a Java compiler, you need the CoffeeMakerAPI Java interface (given in the mentioned chapter) and also the following interface:

   public interface CoffeeMakerImpl {
      void createComponents(CoffeeMakerAPI api);
      void pollComponents();
   }

You can run the application without parameters, and a help message will be printed, but to test your solution you have to connect it with CoffeeMakerGUI, and to do it you must pass as the first argument of the program a class implementing the above CoffeeMakerImpl interface and having a default constructor. So the command to run it could be, for example:
java CoffeeMakerGUI MyCoffeeMakerImpl

The program will instance that passed class and will call to createComponents passing a reference of the CoffeeMakerAPI implementation. Then, it will call to the pollComponents periodically to "wake up" your implementation.

Thanks to Uncle Bob for publishing that interesting problem and solution!

No comments:

Post a Comment