diff --git a/.gitignore b/.gitignore
index 5241a72..e3ed2b0 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1 +1,2 @@
-*.class
\ No newline at end of file
+*.class
+.idea
\ No newline at end of file
diff --git a/Chapter 04 Simple Factory/sample01/Client.java b/Chapter 04 Simple Factory/sample01/Client.java
index 7046500..8ef80cb 100644
--- a/Chapter 04 Simple Factory/sample01/Client.java
+++ b/Chapter 04 Simple Factory/sample01/Client.java
@@ -1,3 +1,5 @@
+package sample01;
+
public class Client
{
public static void main(String args[])
diff --git a/Chapter 04 Simple Factory/sample01/HaierTV.java b/Chapter 04 Simple Factory/sample01/HaierTV.java
index d020697..0fad59a 100644
--- a/Chapter 04 Simple Factory/sample01/HaierTV.java
+++ b/Chapter 04 Simple Factory/sample01/HaierTV.java
@@ -1,3 +1,5 @@
+package sample01;
+
public class HaierTV implements TV
{
public void play()
diff --git a/Chapter 04 Simple Factory/sample01/HisenseTV.java b/Chapter 04 Simple Factory/sample01/HisenseTV.java
index 09c6bb1..3219035 100644
--- a/Chapter 04 Simple Factory/sample01/HisenseTV.java
+++ b/Chapter 04 Simple Factory/sample01/HisenseTV.java
@@ -1,3 +1,5 @@
+package sample01;
+
public class HisenseTV implements TV
{
public void play()
diff --git a/Chapter 04 Simple Factory/sample01/TV.java b/Chapter 04 Simple Factory/sample01/TV.java
index cf0f503..0056d2c 100644
--- a/Chapter 04 Simple Factory/sample01/TV.java
+++ b/Chapter 04 Simple Factory/sample01/TV.java
@@ -1,3 +1,5 @@
+package sample01;
+
public interface TV
{
public void play();
diff --git a/Chapter 04 Simple Factory/sample01/TVFactory.java b/Chapter 04 Simple Factory/sample01/TVFactory.java
index ded671d..073b25e 100644
--- a/Chapter 04 Simple Factory/sample01/TVFactory.java
+++ b/Chapter 04 Simple Factory/sample01/TVFactory.java
@@ -1,20 +1,23 @@
+package sample01;
+
+
public class TVFactory
{
public static TV produceTV(String brand) throws Exception
{
if(brand.equalsIgnoreCase("Haier"))
{
- System.out.println("电视机工厂生产海尔电视机!");
+ System.out.println("Haier");
return new HaierTV();
}
else if(brand.equalsIgnoreCase("Hisense"))
{
- System.out.println("电视机工厂生产海信电视机!");
+ System.out.println("Hisense");
return new HisenseTV();
}
else
{
- throw new Exception("对不起,暂不能生产该品牌电视机!");
+ throw new Exception("Other");
}
}
}
\ No newline at end of file
diff --git a/Chapter 04 Simple Factory/sample01/XMLUtilTV.java b/Chapter 04 Simple Factory/sample01/XMLUtilTV.java
index 69ae749..ca2ad5e 100644
--- a/Chapter 04 Simple Factory/sample01/XMLUtilTV.java
+++ b/Chapter 04 Simple Factory/sample01/XMLUtilTV.java
@@ -1,6 +1,6 @@
+package sample01;
import javax.xml.parsers.*;
import org.w3c.dom.*;
-import org.xml.sax.SAXException;
import java.io.*;
public class XMLUtilTV
{
@@ -13,7 +13,7 @@ public static String getBrandName()
DocumentBuilderFactory dFactory = DocumentBuilderFactory.newInstance();
DocumentBuilder builder = dFactory.newDocumentBuilder();
Document doc;
- doc = builder.parse(new File("configTV.xml"));
+ doc = builder.parse(new File("sample01/configTV.xml"));
//获取包含品牌名称的文本节点
NodeList nl = doc.getElementsByTagName("brandName");
diff --git a/Chapter 04 Simple Factory/sample02/Administrator.java b/Chapter 04 Simple Factory/sample02/Administrator.java
index 0fe57f5..ca472bc 100644
--- a/Chapter 04 Simple Factory/sample02/Administrator.java
+++ b/Chapter 04 Simple Factory/sample02/Administrator.java
@@ -1,3 +1,5 @@
+package sample02;
+
public class Administrator extends User
{
public Administrator()
diff --git a/Chapter 04 Simple Factory/sample02/Client.java b/Chapter 04 Simple Factory/sample02/Client.java
index 0d68acf..5986a9c 100644
--- a/Chapter 04 Simple Factory/sample02/Client.java
+++ b/Chapter 04 Simple Factory/sample02/Client.java
@@ -1,3 +1,5 @@
+package sample02;
+
public class Client
{
public static void main(String args[])
@@ -7,7 +9,7 @@ public static void main(String args[])
User user;
UserDAO userDao=new UserDAO();
int permission=userDao.findPermission("zhangsan","123456");
- user=UserFactory.getUser(permission);
+ user= UserFactory.getUser(permission);
user.sameOperation();
user.diffOperation();
}
diff --git a/Chapter 04 Simple Factory/sample02/Employee.java b/Chapter 04 Simple Factory/sample02/Employee.java
index 96b19a6..f52e7a9 100644
--- a/Chapter 04 Simple Factory/sample02/Employee.java
+++ b/Chapter 04 Simple Factory/sample02/Employee.java
@@ -1,3 +1,5 @@
+package sample02;
+
public class Employee extends User
{
public Employee()
diff --git a/Chapter 04 Simple Factory/sample02/Manager.java b/Chapter 04 Simple Factory/sample02/Manager.java
index fa56435..a6bb262 100644
--- a/Chapter 04 Simple Factory/sample02/Manager.java
+++ b/Chapter 04 Simple Factory/sample02/Manager.java
@@ -1,3 +1,5 @@
+package sample02;
+
public class Manager extends User
{
public Manager()
diff --git a/Chapter 04 Simple Factory/sample02/User.java b/Chapter 04 Simple Factory/sample02/User.java
index 131b3e4..6ffa2f9 100644
--- a/Chapter 04 Simple Factory/sample02/User.java
+++ b/Chapter 04 Simple Factory/sample02/User.java
@@ -1,3 +1,5 @@
+package sample02;
+
public abstract class User
{
public void sameOperation()
diff --git a/Chapter 04 Simple Factory/sample02/UserDAO.java b/Chapter 04 Simple Factory/sample02/UserDAO.java
index 7197120..bcc6176 100644
--- a/Chapter 04 Simple Factory/sample02/UserDAO.java
+++ b/Chapter 04 Simple Factory/sample02/UserDAO.java
@@ -1,3 +1,5 @@
+package sample02;
+
public class UserDAO
{
public int findPermission(String userName,String userPassword)
diff --git a/Chapter 04 Simple Factory/sample02/UserFactory.java b/Chapter 04 Simple Factory/sample02/UserFactory.java
index 74db80e..9bab10e 100644
--- a/Chapter 04 Simple Factory/sample02/UserFactory.java
+++ b/Chapter 04 Simple Factory/sample02/UserFactory.java
@@ -1,3 +1,5 @@
+package sample02;
+
public class UserFactory
{
public static User getUser(int permission)
diff --git a/Chapter 04 Simple Factory/sample02/out/production/Chapter 04 Simple Factory/sample01/configTV.xml b/Chapter 04 Simple Factory/sample02/out/production/Chapter 04 Simple Factory/sample01/configTV.xml
new file mode 100644
index 0000000..2173591
--- /dev/null
+++ b/Chapter 04 Simple Factory/sample02/out/production/Chapter 04 Simple Factory/sample01/configTV.xml
@@ -0,0 +1,4 @@
+
+
+ TCL
+
\ No newline at end of file
diff --git a/Chapter 05 Factory Method/sample01/Client.java b/Chapter 05 Factory Method/sample01/Client.java
index a4fd352..c0c2c9d 100644
--- a/Chapter 05 Factory Method/sample01/Client.java
+++ b/Chapter 05 Factory Method/sample01/Client.java
@@ -1,3 +1,5 @@
+package sample01;
+
public class Client
{
public static void main(String args[])
@@ -6,7 +8,7 @@ public static void main(String args[])
{
TV tv;
TVFactory factory;
- factory=(TVFactory)XMLUtil.getBean();
+ factory=(TVFactory)XMLUtil.getBean("className");
tv=factory.produceTV();
tv.play();
}
diff --git a/Chapter 05 Factory Method/sample01/HaierTV.java b/Chapter 05 Factory Method/sample01/HaierTV.java
index d020697..0fad59a 100644
--- a/Chapter 05 Factory Method/sample01/HaierTV.java
+++ b/Chapter 05 Factory Method/sample01/HaierTV.java
@@ -1,3 +1,5 @@
+package sample01;
+
public class HaierTV implements TV
{
public void play()
diff --git a/Chapter 05 Factory Method/sample01/HaierTVFactory.java b/Chapter 05 Factory Method/sample01/HaierTVFactory.java
index c5ffe5b..b81c427 100644
--- a/Chapter 05 Factory Method/sample01/HaierTVFactory.java
+++ b/Chapter 05 Factory Method/sample01/HaierTVFactory.java
@@ -1,3 +1,5 @@
+package sample01;
+
public class HaierTVFactory implements TVFactory
{
public TV produceTV()
diff --git a/Chapter 05 Factory Method/sample01/HisenseTV.java b/Chapter 05 Factory Method/sample01/HisenseTV.java
index 09c6bb1..3219035 100644
--- a/Chapter 05 Factory Method/sample01/HisenseTV.java
+++ b/Chapter 05 Factory Method/sample01/HisenseTV.java
@@ -1,3 +1,5 @@
+package sample01;
+
public class HisenseTV implements TV
{
public void play()
diff --git a/Chapter 05 Factory Method/sample01/HisenseTVFactory.java b/Chapter 05 Factory Method/sample01/HisenseTVFactory.java
index a65a20c..cceba8a 100644
--- a/Chapter 05 Factory Method/sample01/HisenseTVFactory.java
+++ b/Chapter 05 Factory Method/sample01/HisenseTVFactory.java
@@ -1,3 +1,4 @@
+package sample01;
public class HisenseTVFactory implements TVFactory
{
public TV produceTV()
diff --git a/Chapter 05 Factory Method/sample01/TV.java b/Chapter 05 Factory Method/sample01/TV.java
index cf0f503..36c4913 100644
--- a/Chapter 05 Factory Method/sample01/TV.java
+++ b/Chapter 05 Factory Method/sample01/TV.java
@@ -1,3 +1,4 @@
+package sample01;
public interface TV
{
public void play();
diff --git a/Chapter 05 Factory Method/sample01/TVFactory.java b/Chapter 05 Factory Method/sample01/TVFactory.java
index 2e486c1..484ce47 100644
--- a/Chapter 05 Factory Method/sample01/TVFactory.java
+++ b/Chapter 05 Factory Method/sample01/TVFactory.java
@@ -1,3 +1,4 @@
+package sample01;
public interface TVFactory
{
public TV produceTV();
diff --git a/Chapter 05 Factory Method/sample01/XMLUtil.java b/Chapter 05 Factory Method/sample01/XMLUtil.java
index a56a45f..9daf53e 100644
--- a/Chapter 05 Factory Method/sample01/XMLUtil.java
+++ b/Chapter 05 Factory Method/sample01/XMLUtil.java
@@ -1,3 +1,5 @@
+package sample01;
+
import javax.xml.parsers.*;
import org.w3c.dom.*;
import org.xml.sax.SAXException;
@@ -5,7 +7,7 @@
public class XMLUtil
{
//该方法用于从XML配置文件中提取具体类类名,并返回一个实例对象
- public static Object getBean()
+ public static Object getBean(String className)
{
try
{
@@ -13,10 +15,10 @@ public static Object getBean()
DocumentBuilderFactory dFactory = DocumentBuilderFactory.newInstance();
DocumentBuilder builder = dFactory.newDocumentBuilder();
Document doc;
- doc = builder.parse(new File("config.xml"));
+ doc = builder.parse(new File("./sample01/config.xml"));
//获取包含类名的文本节点
- NodeList nl = doc.getElementsByTagName("className");
+ NodeList nl = doc.getElementsByTagName(className);
Node classNode=nl.item(0).getFirstChild();
String cName=classNode.getNodeValue();
diff --git a/Chapter 05 Factory Method/sample01/config.xml b/Chapter 05 Factory Method/sample01/config.xml
index 44c92a0..c53d641 100644
--- a/Chapter 05 Factory Method/sample01/config.xml
+++ b/Chapter 05 Factory Method/sample01/config.xml
@@ -1,4 +1,5 @@
- HaierTVFactory
+ sample01.HaierTVFactory
+ sample01.project.GifImageReaderFactory
\ No newline at end of file
diff --git a/Chapter 05 Factory Method/sample01/project/GifImageReader.java b/Chapter 05 Factory Method/sample01/project/GifImageReader.java
new file mode 100644
index 0000000..44cc353
--- /dev/null
+++ b/Chapter 05 Factory Method/sample01/project/GifImageReader.java
@@ -0,0 +1,8 @@
+package sample01.project;
+
+public class GifImageReader implements ImageReader{
+ @Override
+ public void readImage() {
+ System.out.println("Read gif image.");
+ }
+}
diff --git a/Chapter 05 Factory Method/sample01/project/GifImageReaderFactory.java b/Chapter 05 Factory Method/sample01/project/GifImageReaderFactory.java
new file mode 100644
index 0000000..6e64d9f
--- /dev/null
+++ b/Chapter 05 Factory Method/sample01/project/GifImageReaderFactory.java
@@ -0,0 +1,9 @@
+package sample01.project;
+
+public class GifImageReaderFactory implements ImageReaderFactory{
+ @Override
+ public ImageReader getReader(){
+ System.out.println("gif image reader factory is producing gif image reader");
+ return new GifImageReader();
+ }
+}
diff --git a/Chapter 05 Factory Method/sample01/project/ImageReader.java b/Chapter 05 Factory Method/sample01/project/ImageReader.java
new file mode 100644
index 0000000..e3ef6e3
--- /dev/null
+++ b/Chapter 05 Factory Method/sample01/project/ImageReader.java
@@ -0,0 +1,5 @@
+package sample01.project;
+
+public interface ImageReader {
+ public void readImage();
+}
diff --git a/Chapter 05 Factory Method/sample01/project/ImageReaderFactory.java b/Chapter 05 Factory Method/sample01/project/ImageReaderFactory.java
new file mode 100644
index 0000000..2273992
--- /dev/null
+++ b/Chapter 05 Factory Method/sample01/project/ImageReaderFactory.java
@@ -0,0 +1,5 @@
+package sample01.project;
+
+public interface ImageReaderFactory {
+ public ImageReader getReader();
+}
diff --git a/Chapter 05 Factory Method/sample01/project/PngImageReader.java b/Chapter 05 Factory Method/sample01/project/PngImageReader.java
new file mode 100644
index 0000000..5870a4d
--- /dev/null
+++ b/Chapter 05 Factory Method/sample01/project/PngImageReader.java
@@ -0,0 +1,8 @@
+package sample01.project;
+
+public class PngImageReader implements ImageReader{
+ @Override
+ public void readImage() {
+ System.out.println("Png image reader read images.");
+ }
+}
diff --git a/Chapter 05 Factory Method/sample01/project/PngImageReaderFactory.java b/Chapter 05 Factory Method/sample01/project/PngImageReaderFactory.java
new file mode 100644
index 0000000..e7403e5
--- /dev/null
+++ b/Chapter 05 Factory Method/sample01/project/PngImageReaderFactory.java
@@ -0,0 +1,9 @@
+package sample01.project;
+
+public class PngImageReaderFactory implements ImageReaderFactory {
+ @Override
+ public ImageReader getReader() {
+ System.out.println("Png Image Reader Factory start product Image Reader");
+ return new PngImageReader();
+ }
+}
diff --git a/Chapter 05 Factory Method/sample01/project/client/Client.java b/Chapter 05 Factory Method/sample01/project/client/Client.java
new file mode 100644
index 0000000..3d0462b
--- /dev/null
+++ b/Chapter 05 Factory Method/sample01/project/client/Client.java
@@ -0,0 +1,23 @@
+package sample01.project.client;
+
+import sample01.project.ImageReader;
+import sample01.project.ImageReaderFactory;
+import sample01.XMLUtil;
+
+public class Client {
+ public static void main(String args[])
+ {
+ try
+ {
+ ImageReader ir;
+ ImageReaderFactory irf;
+ irf = (ImageReaderFactory) XMLUtil.getBean("ImageReaderFactory");
+ ir = irf.getReader();
+ ir.readImage();
+ }
+ catch(Exception e)
+ {
+ System.out.println(e.getMessage());
+ }
+ }
+}
diff --git a/Chapter 06 Abstract Factory/sample01/AirConditioner.java b/Chapter 06 Abstract Factory/sample01/AirConditioner.java
index cac52c8..4983ccc 100644
--- a/Chapter 06 Abstract Factory/sample01/AirConditioner.java
+++ b/Chapter 06 Abstract Factory/sample01/AirConditioner.java
@@ -1,3 +1,4 @@
+package sample01;
public interface AirConditioner
{
public void changeTemperature();
diff --git a/Chapter 06 Abstract Factory/sample01/Client.java b/Chapter 06 Abstract Factory/sample01/Client.java
index 993d13a..01ed79e 100644
--- a/Chapter 06 Abstract Factory/sample01/Client.java
+++ b/Chapter 06 Abstract Factory/sample01/Client.java
@@ -1,3 +1,4 @@
+package sample01;
public class Client
{
public static void main(String args[])
diff --git a/Chapter 06 Abstract Factory/sample01/EFactory.java b/Chapter 06 Abstract Factory/sample01/EFactory.java
index e9d52e0..556c63e 100644
--- a/Chapter 06 Abstract Factory/sample01/EFactory.java
+++ b/Chapter 06 Abstract Factory/sample01/EFactory.java
@@ -1,3 +1,4 @@
+package sample01;
public interface EFactory
{
public Television produceTelevision();
diff --git a/Chapter 06 Abstract Factory/sample01/HaierFactory.java b/Chapter 06 Abstract Factory/sample01/HaierFactory.java
index 9f7e8e7..8bd8d09 100644
--- a/Chapter 06 Abstract Factory/sample01/HaierFactory.java
+++ b/Chapter 06 Abstract Factory/sample01/HaierFactory.java
@@ -1,3 +1,4 @@
+package sample01;
public class HaierFactory implements EFactory
{
public Television produceTelevision()
diff --git a/Chapter 06 Abstract Factory/sample01/HaierTelevision.java b/Chapter 06 Abstract Factory/sample01/HaierTelevision.java
index b42f0d0..3101229 100644
--- a/Chapter 06 Abstract Factory/sample01/HaierTelevision.java
+++ b/Chapter 06 Abstract Factory/sample01/HaierTelevision.java
@@ -1,3 +1,4 @@
+package sample01;
public class HaierTelevision implements Television
{
public void play()
diff --git a/Chapter 06 Abstract Factory/sample01/HairAirConditioner.java b/Chapter 06 Abstract Factory/sample01/HairAirConditioner.java
index 33b0313..51f70d0 100644
--- a/Chapter 06 Abstract Factory/sample01/HairAirConditioner.java
+++ b/Chapter 06 Abstract Factory/sample01/HairAirConditioner.java
@@ -1,3 +1,4 @@
+package sample01;
public class HairAirConditioner implements AirConditioner
{
public void changeTemperature()
diff --git a/Chapter 06 Abstract Factory/sample01/TCLAirConditioner.java b/Chapter 06 Abstract Factory/sample01/TCLAirConditioner.java
index e02ea91..f35e870 100644
--- a/Chapter 06 Abstract Factory/sample01/TCLAirConditioner.java
+++ b/Chapter 06 Abstract Factory/sample01/TCLAirConditioner.java
@@ -1,3 +1,4 @@
+package sample01;
public class TCLAirConditioner implements AirConditioner
{
public void changeTemperature()
diff --git a/Chapter 06 Abstract Factory/sample01/TCLFactory.java b/Chapter 06 Abstract Factory/sample01/TCLFactory.java
index 7258e26..14c5104 100644
--- a/Chapter 06 Abstract Factory/sample01/TCLFactory.java
+++ b/Chapter 06 Abstract Factory/sample01/TCLFactory.java
@@ -1,3 +1,4 @@
+package sample01;
public class TCLFactory implements EFactory
{
public Television produceTelevision()
diff --git a/Chapter 06 Abstract Factory/sample01/TCLTelevision.java b/Chapter 06 Abstract Factory/sample01/TCLTelevision.java
index 698b2f9..04629ee 100644
--- a/Chapter 06 Abstract Factory/sample01/TCLTelevision.java
+++ b/Chapter 06 Abstract Factory/sample01/TCLTelevision.java
@@ -1,3 +1,4 @@
+package sample01;
public class TCLTelevision implements Television
{
public void play()
diff --git a/Chapter 06 Abstract Factory/sample01/Television.java b/Chapter 06 Abstract Factory/sample01/Television.java
index 30fd67e..dbcc443 100644
--- a/Chapter 06 Abstract Factory/sample01/Television.java
+++ b/Chapter 06 Abstract Factory/sample01/Television.java
@@ -1,3 +1,4 @@
+package sample01;
public interface Television
{
public void play();
diff --git a/Chapter 06 Abstract Factory/sample01/XMLUtil.java b/Chapter 06 Abstract Factory/sample01/XMLUtil.java
index a56a45f..9855e1d 100644
--- a/Chapter 06 Abstract Factory/sample01/XMLUtil.java
+++ b/Chapter 06 Abstract Factory/sample01/XMLUtil.java
@@ -1,3 +1,4 @@
+package sample01;
import javax.xml.parsers.*;
import org.w3c.dom.*;
import org.xml.sax.SAXException;
@@ -13,7 +14,7 @@ public static Object getBean()
DocumentBuilderFactory dFactory = DocumentBuilderFactory.newInstance();
DocumentBuilder builder = dFactory.newDocumentBuilder();
Document doc;
- doc = builder.parse(new File("config.xml"));
+ doc = builder.parse(new File("./sample01/config.xml"));
//获取包含类名的文本节点
NodeList nl = doc.getElementsByTagName("className");
diff --git a/Chapter 06 Abstract Factory/sample01/config.xml b/Chapter 06 Abstract Factory/sample01/config.xml
index b70704d..9b7cb7d 100644
--- a/Chapter 06 Abstract Factory/sample01/config.xml
+++ b/Chapter 06 Abstract Factory/sample01/config.xml
@@ -1,4 +1,4 @@
- TCLFactory
+ sample01.TCLFactory
\ No newline at end of file
diff --git a/Chapter 06 Abstract Factory/sample01/homework/Client/GameClient.java b/Chapter 06 Abstract Factory/sample01/homework/Client/GameClient.java
new file mode 100644
index 0000000..b4fdb22
--- /dev/null
+++ b/Chapter 06 Abstract Factory/sample01/homework/Client/GameClient.java
@@ -0,0 +1,19 @@
+package sample01.homework.Client;
+
+import sample01.homework.ControllerFactory;
+import sample01.homework.InterfaceController;
+import sample01.homework.LinuxFactory;
+import sample01.homework.OperationController;
+
+public class GameClient {
+ public static void main(String[] args) {
+ ControllerFactory cf;
+ InterfaceController ic;
+ OperationController oc;
+ cf = new LinuxFactory();
+ ic = cf.getInterfaceController();
+ oc = cf.getOperationController();
+ ic.control();
+ oc.control();
+ }
+}
diff --git a/Chapter 06 Abstract Factory/sample01/homework/ControllerFactory.java b/Chapter 06 Abstract Factory/sample01/homework/ControllerFactory.java
new file mode 100644
index 0000000..ffe1f7b
--- /dev/null
+++ b/Chapter 06 Abstract Factory/sample01/homework/ControllerFactory.java
@@ -0,0 +1,7 @@
+package sample01.homework;
+
+public interface ControllerFactory {
+ InterfaceController getInterfaceController();
+
+ OperationController getOperationController();
+}
diff --git a/Chapter 06 Abstract Factory/sample01/homework/InterfaceController.java b/Chapter 06 Abstract Factory/sample01/homework/InterfaceController.java
new file mode 100644
index 0000000..70cee63
--- /dev/null
+++ b/Chapter 06 Abstract Factory/sample01/homework/InterfaceController.java
@@ -0,0 +1,5 @@
+package sample01.homework;
+
+public interface InterfaceController {
+ public void control();
+}
diff --git a/Chapter 06 Abstract Factory/sample01/homework/LinuxFactory.java b/Chapter 06 Abstract Factory/sample01/homework/LinuxFactory.java
new file mode 100644
index 0000000..9eb3206
--- /dev/null
+++ b/Chapter 06 Abstract Factory/sample01/homework/LinuxFactory.java
@@ -0,0 +1,13 @@
+package sample01.homework;
+
+public class LinuxFactory implements ControllerFactory {
+ @Override
+ public InterfaceController getInterfaceController() {
+ return new LinuxInterfaceController();
+ }
+
+ @Override
+ public OperationController getOperationController() {
+ return new LinuxOperationController();
+ }
+}
diff --git a/Chapter 06 Abstract Factory/sample01/homework/LinuxInterfaceController.java b/Chapter 06 Abstract Factory/sample01/homework/LinuxInterfaceController.java
new file mode 100644
index 0000000..b7cdcc8
--- /dev/null
+++ b/Chapter 06 Abstract Factory/sample01/homework/LinuxInterfaceController.java
@@ -0,0 +1,8 @@
+package sample01.homework;
+
+public class LinuxInterfaceController implements InterfaceController {
+ @Override
+ public void control() {
+ System.out.println("Linux interface is controlling");
+ }
+}
diff --git a/Chapter 06 Abstract Factory/sample01/homework/LinuxOperationController.java b/Chapter 06 Abstract Factory/sample01/homework/LinuxOperationController.java
new file mode 100644
index 0000000..8cc8bdf
--- /dev/null
+++ b/Chapter 06 Abstract Factory/sample01/homework/LinuxOperationController.java
@@ -0,0 +1,8 @@
+package sample01.homework;
+
+public class LinuxOperationController implements OperationController {
+ @Override
+ public void control() {
+ System.out.println("linux operation is controlling");
+ }
+}
diff --git a/Chapter 06 Abstract Factory/sample01/homework/OperationController.java b/Chapter 06 Abstract Factory/sample01/homework/OperationController.java
new file mode 100644
index 0000000..26b34dd
--- /dev/null
+++ b/Chapter 06 Abstract Factory/sample01/homework/OperationController.java
@@ -0,0 +1,5 @@
+package sample01.homework;
+
+public interface OperationController {
+ public void control();
+}
diff --git a/Chapter 06 Abstract Factory/sample01/homework/WindowsFactory.java b/Chapter 06 Abstract Factory/sample01/homework/WindowsFactory.java
new file mode 100644
index 0000000..cd0bcbc
--- /dev/null
+++ b/Chapter 06 Abstract Factory/sample01/homework/WindowsFactory.java
@@ -0,0 +1,13 @@
+package sample01.homework;
+
+public class WindowsFactory implements ControllerFactory {
+ @Override
+ public InterfaceController getInterfaceController() {
+ return new WindowsInterfaceController();
+ }
+
+ @Override
+ public OperationController getOperationController() {
+ return new WindowsOperationController();
+ }
+}
diff --git a/Chapter 06 Abstract Factory/sample01/homework/WindowsInterfaceController.java b/Chapter 06 Abstract Factory/sample01/homework/WindowsInterfaceController.java
new file mode 100644
index 0000000..6224b8f
--- /dev/null
+++ b/Chapter 06 Abstract Factory/sample01/homework/WindowsInterfaceController.java
@@ -0,0 +1,8 @@
+package sample01.homework;
+
+public class WindowsInterfaceController implements InterfaceController {
+ @Override
+ public void control() {
+ System.out.println("Windows interface is controlling.");
+ }
+}
diff --git a/Chapter 06 Abstract Factory/sample01/homework/WindowsOperationController.java b/Chapter 06 Abstract Factory/sample01/homework/WindowsOperationController.java
new file mode 100644
index 0000000..a9323e7
--- /dev/null
+++ b/Chapter 06 Abstract Factory/sample01/homework/WindowsOperationController.java
@@ -0,0 +1,8 @@
+package sample01.homework;
+
+public class WindowsOperationController implements OperationController {
+ @Override
+ public void control() {
+ System.out.println("Windows Operation is controlling");
+ }
+}
diff --git a/Chapter 08 Prototype/homework/Address.java b/Chapter 08 Prototype/homework/Address.java
new file mode 100644
index 0000000..db68bf7
--- /dev/null
+++ b/Chapter 08 Prototype/homework/Address.java
@@ -0,0 +1,20 @@
+public class Address implements Cloneable {
+ private String addNo;
+ public Address clone(){
+ Address add = null;
+ try {
+ add = (Address)super.clone();
+ } catch (CloneNotSupportedException e) {
+ System.out.println("class not cloneable.");
+ }
+ return add;
+ }
+
+ public String getAddNo() {
+ return addNo;
+ }
+
+ public void setAddNo(String addNo) {
+ this.addNo = addNo;
+ }
+}
diff --git a/Chapter 08 Prototype/homework/Customer.java b/Chapter 08 Prototype/homework/Customer.java
new file mode 100644
index 0000000..398fc89
--- /dev/null
+++ b/Chapter 08 Prototype/homework/Customer.java
@@ -0,0 +1,20 @@
+public class Customer {
+ private Address addr;
+
+ public Address getAddr() {
+ return addr;
+ }
+
+ public void setAddr(Address addr) {
+ this.addr = addr;
+ }
+
+ public static void main(String[] args) {
+ Customer c = new Customer();
+ Address add = new Address();
+ add.setAddNo("aaa");
+ c.setAddr(add);
+ Address add2 = c.getAddr().clone();
+ System.out.println(add == add2);
+ }
+}
diff --git a/Chapter 09 Singleton/homework/EhanSingleton.java b/Chapter 09 Singleton/homework/EhanSingleton.java
new file mode 100644
index 0000000..6d9ce9b
--- /dev/null
+++ b/Chapter 09 Singleton/homework/EhanSingleton.java
@@ -0,0 +1,9 @@
+public class EhanSingleton {
+ // Ehan model, initialize while create class
+ private static final EhanSingleton instance = new EhanSingleton();
+ private EhanSingleton(){};
+
+ public static EhanSingleton getInstance(){
+ return instance;
+ }
+}
diff --git a/Chapter 09 Singleton/homework/IoDHSingleton.java b/Chapter 09 Singleton/homework/IoDHSingleton.java
new file mode 100644
index 0000000..88520a6
--- /dev/null
+++ b/Chapter 09 Singleton/homework/IoDHSingleton.java
@@ -0,0 +1,14 @@
+public class IoDHSingleton {
+ // rewrite builder
+ private IoDHSingleton() {
+ }
+
+ // static inner class
+ private static class HolderClass {
+ private static final IoDHSingleton instance = new IoDHSingleton();
+ }
+
+ public static IoDHSingleton getInstance() {
+ return HolderClass.instance;
+ }
+}
diff --git a/Chapter 09 Singleton/homework/LanhanSingleton.java b/Chapter 09 Singleton/homework/LanhanSingleton.java
new file mode 100644
index 0000000..40e6382
--- /dev/null
+++ b/Chapter 09 Singleton/homework/LanhanSingleton.java
@@ -0,0 +1,18 @@
+public class LanhanSingleton {
+ private volatile static LanhanSingleton instance = null;
+ private LanhanSingleton(){}
+
+ public LanhanSingleton getInstance() {
+ // first check
+ if (null == instance) {
+ // lock class
+ synchronized (LanhanSingleton.class) {
+ // second check
+ if (null == instance) {
+ instance = new LanhanSingleton();
+ }
+ }
+ }
+ return instance;
+ }
+}
diff --git a/Chapter 10 Adapter/sample02/config.xml b/Chapter 10 Adapter/sample02/config.xml
index 323ecb8..c320850 100644
--- a/Chapter 10 Adapter/sample02/config.xml
+++ b/Chapter 10 Adapter/sample02/config.xml
@@ -1,4 +1,4 @@
- NewCipherAdapter
+ CipherAdapter
\ No newline at end of file
diff --git a/Chapter 11 Bridge/homework/Client.java b/Chapter 11 Bridge/homework/Client.java
new file mode 100644
index 0000000..21fdc2f
--- /dev/null
+++ b/Chapter 11 Bridge/homework/Client.java
@@ -0,0 +1,8 @@
+public class Client {
+ public static void main(String[] args) {
+ DbConnector connector = new PostgrelDBConnector();
+ Generator generator = new PDFGenerator();
+ generator.setConnector(connector);
+ generator.exportFile();
+ }
+}
diff --git a/Chapter 11 Bridge/homework/DbConnector.java b/Chapter 11 Bridge/homework/DbConnector.java
new file mode 100644
index 0000000..8877b65
--- /dev/null
+++ b/Chapter 11 Bridge/homework/DbConnector.java
@@ -0,0 +1,3 @@
+public interface DbConnector {
+ void connectDB();
+}
diff --git a/Chapter 11 Bridge/homework/Generator.java b/Chapter 11 Bridge/homework/Generator.java
new file mode 100644
index 0000000..08a7a2a
--- /dev/null
+++ b/Chapter 11 Bridge/homework/Generator.java
@@ -0,0 +1,10 @@
+abstract class Generator {
+ protected DbConnector connector;
+
+ // set connector
+ public void setConnector(DbConnector connector) {
+ this.connector = connector;
+ }
+
+ abstract void exportFile();
+}
diff --git a/Chapter 11 Bridge/homework/MySQLDBConnector.java b/Chapter 11 Bridge/homework/MySQLDBConnector.java
new file mode 100644
index 0000000..ae449c1
--- /dev/null
+++ b/Chapter 11 Bridge/homework/MySQLDBConnector.java
@@ -0,0 +1,6 @@
+public class MySQLDBConnector implements DbConnector {
+ @Override
+ public void connectDB() {
+ System.out.println("read from mysql db");
+ }
+}
diff --git a/Chapter 11 Bridge/homework/PDFGenerator.java b/Chapter 11 Bridge/homework/PDFGenerator.java
new file mode 100644
index 0000000..d5f932c
--- /dev/null
+++ b/Chapter 11 Bridge/homework/PDFGenerator.java
@@ -0,0 +1,7 @@
+public class PDFGenerator extends Generator {
+ @Override
+ void exportFile() {
+ this.connector.connectDB();
+ System.out.println("generate PDF file.");
+ }
+}
diff --git a/Chapter 11 Bridge/homework/PostgrelDBConnector.java b/Chapter 11 Bridge/homework/PostgrelDBConnector.java
new file mode 100644
index 0000000..a7fe717
--- /dev/null
+++ b/Chapter 11 Bridge/homework/PostgrelDBConnector.java
@@ -0,0 +1,6 @@
+public class PostgrelDBConnector implements DbConnector {
+ @Override
+ public void connectDB() {
+ System.out.println("read from postgrel db.");
+ }
+}
diff --git a/Chapter 11 Bridge/homework/TXTGenerator.java b/Chapter 11 Bridge/homework/TXTGenerator.java
new file mode 100644
index 0000000..be1be94
--- /dev/null
+++ b/Chapter 11 Bridge/homework/TXTGenerator.java
@@ -0,0 +1,7 @@
+public class TXTGenerator extends Generator {
+ @Override
+ void exportFile() {
+ this.connector.connectDB();
+ System.out.println("generate txt file.");
+ }
+}
diff --git a/Chapter 11 Bridge/homework/UML.png b/Chapter 11 Bridge/homework/UML.png
new file mode 100644
index 0000000..6d58475
Binary files /dev/null and b/Chapter 11 Bridge/homework/UML.png differ
diff --git a/Chapter 11 Bridge/homework/XMLGenerator.java b/Chapter 11 Bridge/homework/XMLGenerator.java
new file mode 100644
index 0000000..3e058bd
--- /dev/null
+++ b/Chapter 11 Bridge/homework/XMLGenerator.java
@@ -0,0 +1,7 @@
+public class XMLGenerator extends Generator {
+ @Override
+ void exportFile() {
+ this.connector.connectDB();
+ System.out.println("generate xml file.");
+ }
+}