Info

3 public static Object newInstance(String className) {

6 els = Class.forName(className);// create the class

8 catch (ClassNotFoundException enfe) {

9 System.out.println("can't find class named: " +className);

11 Object newObject = null;

14 newObject = cls.newlnstance(); // Create the instance

16 catch (InstantiationException ie) {

17 System.out.printlnC'can't instantiate class named: " +className);

19 catch (IllegalAccessException iae) {

20 System.out.printlnC'can't access class named: " + className); Figure 9-2. The implementation in Java of Strategy and AbstractFactory patterns (Part 1 of 2).

23 return newObject;

Figure 9-2. The implementation in Java of Strategy and AbstractFactory patterns (Part 2 of 2).

plant^Plant soil=soil we at he r=we at he r Dat aF r omfi1e

Figure 9-3. Example of configuration file.

0 0

Post a comment