forked from hazukac/DesignPatterns
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathFactory.java
More file actions
21 lines (20 loc) · 758 Bytes
/
Factory.java
File metadata and controls
21 lines (20 loc) · 758 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
package factory;
public abstract class Factory {
public static Factory getFactory(String className) {
Factory factory = null;
try {
// clazz ? or klass
Class clazz = Class.forName(className);
Object instance = clazz.newInstance();
factory = (Factory)instance;
} catch (ClassNotFoundException e) {
System.err.println("クラス名 " + className + " が見つかりませーん");
} catch (Exception e) {
e.printStackTrace();
}
return factory;
}
public abstract Link createLink(String caption, String url);
public abstract Tray createTray(String caption);
public abstract Page createPage(String title, String author);
}