1 Reply Latest reply: Oct 29, 2012 9:27 AM by gimbal2 RSS

    Design issues


      We will make a library ( tool library) that contains different tools that we use for testing. For each test project we will use this tool library to write tests that use these tools.
      Lets say I have tool A, B, C as java libraries. We include all these tools in tools library. They should be easy accessible in test. Lets say that in my test project ( code) we access the tool like:



      What I would like is to have some kind of Manager where I can request the tool from.
      Tool toolA = Manager.getTool("ToolA");

      Is there a better way to do this?
      This will give a common interface for accessing the tools. Any ideas of how we can implement this. What technique would I use to be able to access my different tool libraries?

      I am open for discussions.


        • 1. Re: Design issues
          Class.forName() combined with a simple convention can work. Lets set an example: you have three tools; ToolA, ToolB, ToolC. The convention could be that the code will try to find a matching Class for ToolA in the package "com.mycompany.toola.ToolA". So the convention is "com.mycompany.<toolclasslowercase>.ToolClass". All tools implement some common interface so you can refer to them in a generic way without ever having to deal with the ToolA, ToolB or ToolC implementation classes directly in your code.

          half-finished example:
          public Tool getTool(String name){
            Class clz = Class.forName("com.mycompany." + name.toLowerCase() + "." + name);
            return (Tool) clz.newInstance();
          Add exception handling and such.