\n");
+ return buffer.toString();
+ }
+
+}
diff --git a/src/main/java/com/mashibing/dp/abstractfactory/AK47.java b/src/main/java/com/shenyy/dp/abstractfactory/example02/AK47.java
similarity index 70%
rename from src/main/java/com/mashibing/dp/abstractfactory/AK47.java
rename to src/main/java/com/shenyy/dp/abstractfactory/example02/AK47.java
index 68b49a9..3d21ad4 100644
--- a/src/main/java/com/mashibing/dp/abstractfactory/AK47.java
+++ b/src/main/java/com/shenyy/dp/abstractfactory/example02/AK47.java
@@ -1,4 +1,4 @@
-package com.mashibing.dp.abstractfactory;
+package com.shenyy.dp.abstractfactory.example02;
public class AK47 extends Weapon{
public void shoot() {
diff --git a/src/main/java/com/mashibing/dp/abstractfactory/AbastractFactory.java b/src/main/java/com/shenyy/dp/abstractfactory/example02/AbastractFactory.java
similarity index 75%
rename from src/main/java/com/mashibing/dp/abstractfactory/AbastractFactory.java
rename to src/main/java/com/shenyy/dp/abstractfactory/example02/AbastractFactory.java
index 43baad9..a4fb0a3 100644
--- a/src/main/java/com/mashibing/dp/abstractfactory/AbastractFactory.java
+++ b/src/main/java/com/shenyy/dp/abstractfactory/example02/AbastractFactory.java
@@ -1,4 +1,4 @@
-package com.mashibing.dp.abstractfactory;
+package com.shenyy.dp.abstractfactory.example02;
public abstract class AbastractFactory {
abstract Food createFood();
diff --git a/src/main/java/com/mashibing/dp/abstractfactory/Bread.java b/src/main/java/com/shenyy/dp/abstractfactory/example02/Bread.java
similarity index 68%
rename from src/main/java/com/mashibing/dp/abstractfactory/Bread.java
rename to src/main/java/com/shenyy/dp/abstractfactory/example02/Bread.java
index cbd0989..dbe6d52 100644
--- a/src/main/java/com/mashibing/dp/abstractfactory/Bread.java
+++ b/src/main/java/com/shenyy/dp/abstractfactory/example02/Bread.java
@@ -1,4 +1,4 @@
-package com.mashibing.dp.abstractfactory;
+package com.shenyy.dp.abstractfactory.example02;
public class Bread extends Food{
public void printName() {
diff --git a/src/main/java/com/mashibing/dp/abstractfactory/Broom.java b/src/main/java/com/shenyy/dp/abstractfactory/example02/Broom.java
similarity index 71%
rename from src/main/java/com/mashibing/dp/abstractfactory/Broom.java
rename to src/main/java/com/shenyy/dp/abstractfactory/example02/Broom.java
index 79c3358..95cf1aa 100644
--- a/src/main/java/com/mashibing/dp/abstractfactory/Broom.java
+++ b/src/main/java/com/shenyy/dp/abstractfactory/example02/Broom.java
@@ -1,4 +1,4 @@
-package com.mashibing.dp.abstractfactory;
+package com.shenyy.dp.abstractfactory.example02;
public class Broom extends Vehicle{
public void go() {
diff --git a/src/main/java/com/mashibing/dp/abstractfactory/Car.java b/src/main/java/com/shenyy/dp/abstractfactory/example02/Car.java
similarity index 70%
rename from src/main/java/com/mashibing/dp/abstractfactory/Car.java
rename to src/main/java/com/shenyy/dp/abstractfactory/example02/Car.java
index d589784..5b747a0 100644
--- a/src/main/java/com/mashibing/dp/abstractfactory/Car.java
+++ b/src/main/java/com/shenyy/dp/abstractfactory/example02/Car.java
@@ -1,4 +1,4 @@
-package com.mashibing.dp.abstractfactory;
+package com.shenyy.dp.abstractfactory.example02;
public class Car extends Vehicle{
diff --git a/src/main/java/com/mashibing/dp/abstractfactory/Food.java b/src/main/java/com/shenyy/dp/abstractfactory/example02/Food.java
similarity index 55%
rename from src/main/java/com/mashibing/dp/abstractfactory/Food.java
rename to src/main/java/com/shenyy/dp/abstractfactory/example02/Food.java
index 9d37d05..e282939 100644
--- a/src/main/java/com/mashibing/dp/abstractfactory/Food.java
+++ b/src/main/java/com/shenyy/dp/abstractfactory/example02/Food.java
@@ -1,4 +1,4 @@
-package com.mashibing.dp.abstractfactory;
+package com.shenyy.dp.abstractfactory.example02;
public abstract class Food {
abstract void printName();
diff --git a/src/main/java/com/mashibing/dp/abstractfactory/MagicFactory.java b/src/main/java/com/shenyy/dp/abstractfactory/example02/MagicFactory.java
similarity index 85%
rename from src/main/java/com/mashibing/dp/abstractfactory/MagicFactory.java
rename to src/main/java/com/shenyy/dp/abstractfactory/example02/MagicFactory.java
index b1d0032..5d0a3ca 100644
--- a/src/main/java/com/mashibing/dp/abstractfactory/MagicFactory.java
+++ b/src/main/java/com/shenyy/dp/abstractfactory/example02/MagicFactory.java
@@ -1,4 +1,4 @@
-package com.mashibing.dp.abstractfactory;
+package com.shenyy.dp.abstractfactory.example02;
public class MagicFactory extends AbastractFactory {
@Override
diff --git a/src/main/java/com/mashibing/dp/abstractfactory/MagicStick.java b/src/main/java/com/shenyy/dp/abstractfactory/example02/MagicStick.java
similarity index 70%
rename from src/main/java/com/mashibing/dp/abstractfactory/MagicStick.java
rename to src/main/java/com/shenyy/dp/abstractfactory/example02/MagicStick.java
index 2bfb0a7..5750f71 100644
--- a/src/main/java/com/mashibing/dp/abstractfactory/MagicStick.java
+++ b/src/main/java/com/shenyy/dp/abstractfactory/example02/MagicStick.java
@@ -1,4 +1,4 @@
-package com.mashibing.dp.abstractfactory;
+package com.shenyy.dp.abstractfactory.example02;
public class MagicStick extends Weapon{
public void shoot() {
diff --git a/src/main/java/com/mashibing/dp/abstractfactory/Main.java b/src/main/java/com/shenyy/dp/abstractfactory/example02/Main.java
similarity index 85%
rename from src/main/java/com/mashibing/dp/abstractfactory/Main.java
rename to src/main/java/com/shenyy/dp/abstractfactory/example02/Main.java
index 4437d69..3eb453b 100644
--- a/src/main/java/com/mashibing/dp/abstractfactory/Main.java
+++ b/src/main/java/com/shenyy/dp/abstractfactory/example02/Main.java
@@ -1,4 +1,4 @@
-package com.mashibing.dp.abstractfactory;
+package com.shenyy.dp.abstractfactory.example02;
public class Main {
public static void main(String[] args) {
@@ -11,4 +11,4 @@ public static void main(String[] args) {
Food b = f.createFood();
b.printName();
}
-}
+}
\ No newline at end of file
diff --git a/src/main/java/com/mashibing/dp/abstractfactory/ModernFactory.java b/src/main/java/com/shenyy/dp/abstractfactory/example02/ModernFactory.java
similarity index 85%
rename from src/main/java/com/mashibing/dp/abstractfactory/ModernFactory.java
rename to src/main/java/com/shenyy/dp/abstractfactory/example02/ModernFactory.java
index 5bd7d8e..6aef57c 100644
--- a/src/main/java/com/mashibing/dp/abstractfactory/ModernFactory.java
+++ b/src/main/java/com/shenyy/dp/abstractfactory/example02/ModernFactory.java
@@ -1,4 +1,4 @@
-package com.mashibing.dp.abstractfactory;
+package com.shenyy.dp.abstractfactory.example02;
public class ModernFactory extends AbastractFactory {
diff --git a/src/main/java/com/mashibing/dp/abstractfactory/MushRoom.java b/src/main/java/com/shenyy/dp/abstractfactory/example02/MushRoom.java
similarity index 69%
rename from src/main/java/com/mashibing/dp/abstractfactory/MushRoom.java
rename to src/main/java/com/shenyy/dp/abstractfactory/example02/MushRoom.java
index 95bf520..b1695dd 100644
--- a/src/main/java/com/mashibing/dp/abstractfactory/MushRoom.java
+++ b/src/main/java/com/shenyy/dp/abstractfactory/example02/MushRoom.java
@@ -1,4 +1,4 @@
-package com.mashibing.dp.abstractfactory;
+package com.shenyy.dp.abstractfactory.example02;
public class MushRoom extends Food{
public void printName() {
diff --git a/src/main/java/com/mashibing/dp/abstractfactory/Vehicle.java b/src/main/java/com/shenyy/dp/abstractfactory/example02/Vehicle.java
similarity index 59%
rename from src/main/java/com/mashibing/dp/abstractfactory/Vehicle.java
rename to src/main/java/com/shenyy/dp/abstractfactory/example02/Vehicle.java
index 9ca995a..420b7b0 100644
--- a/src/main/java/com/mashibing/dp/abstractfactory/Vehicle.java
+++ b/src/main/java/com/shenyy/dp/abstractfactory/example02/Vehicle.java
@@ -1,4 +1,4 @@
-package com.mashibing.dp.abstractfactory;
+package com.shenyy.dp.abstractfactory.example02;
public abstract class Vehicle { //interface
abstract void go();
diff --git a/src/main/java/com/mashibing/dp/abstractfactory/Weapon.java b/src/main/java/com/shenyy/dp/abstractfactory/example02/Weapon.java
similarity index 55%
rename from src/main/java/com/mashibing/dp/abstractfactory/Weapon.java
rename to src/main/java/com/shenyy/dp/abstractfactory/example02/Weapon.java
index e012003..b52ec2b 100644
--- a/src/main/java/com/mashibing/dp/abstractfactory/Weapon.java
+++ b/src/main/java/com/shenyy/dp/abstractfactory/example02/Weapon.java
@@ -1,4 +1,4 @@
-package com.mashibing.dp.abstractfactory;
+package com.shenyy.dp.abstractfactory.example02;
public abstract class Weapon {
abstract void shoot();
diff --git a/src/main/java/com/shenyy/dp/abstractfactory/exercise2/Car.java b/src/main/java/com/shenyy/dp/abstractfactory/exercise2/Car.java
new file mode 100644
index 0000000..3597e09
--- /dev/null
+++ b/src/main/java/com/shenyy/dp/abstractfactory/exercise2/Car.java
@@ -0,0 +1,13 @@
+package com.shenyy.dp.abstractfactory.exercise2;
+
+abstract class Car { //interface
+ protected CarType carType;
+ protected Location location;
+
+ public Car(CarType carType, Location location) {
+ this.carType = carType;
+ this.location = location;
+ }
+
+ abstract void construct();
+}
diff --git a/src/main/java/com/shenyy/dp/abstractfactory/exercise2/CarFactory.java b/src/main/java/com/shenyy/dp/abstractfactory/exercise2/CarFactory.java
new file mode 100644
index 0000000..c080a4e
--- /dev/null
+++ b/src/main/java/com/shenyy/dp/abstractfactory/exercise2/CarFactory.java
@@ -0,0 +1,9 @@
+package com.shenyy.dp.abstractfactory.exercise2;
+
+abstract class CarFactory {
+ abstract Car createMini();
+
+ abstract Car createMicro();
+
+ abstract Car createLuxury();
+}
diff --git a/src/main/java/com/shenyy/dp/abstractfactory/exercise2/CarType.java b/src/main/java/com/shenyy/dp/abstractfactory/exercise2/CarType.java
new file mode 100644
index 0000000..8e1f7b6
--- /dev/null
+++ b/src/main/java/com/shenyy/dp/abstractfactory/exercise2/CarType.java
@@ -0,0 +1,7 @@
+package com.shenyy.dp.abstractfactory.exercise2;
+
+public enum CarType {
+ MICRO,
+ MINI,
+ LUXURY
+}
diff --git a/src/main/java/com/shenyy/dp/abstractfactory/exercise2/ChinaFactory.java b/src/main/java/com/shenyy/dp/abstractfactory/exercise2/ChinaFactory.java
new file mode 100644
index 0000000..0b736d7
--- /dev/null
+++ b/src/main/java/com/shenyy/dp/abstractfactory/exercise2/ChinaFactory.java
@@ -0,0 +1,21 @@
+package com.shenyy.dp.abstractfactory.exercise2;
+
+public class ChinaFactory extends CarFactory {
+ @Override
+ Car createMini() {
+ Car car = new MiniCar(CarType.MINI,Location.CHINA);
+ return car;
+ }
+
+ @Override
+ Car createMicro() {
+ Car car = new MicroCar(CarType.MICRO,Location.CHINA);
+ return car;
+ }
+
+ @Override
+ Car createLuxury() {
+ Car car = new MicroCar(CarType.LUXURY,Location.CHINA);
+ return car;
+ }
+}
diff --git a/src/main/java/com/shenyy/dp/abstractfactory/exercise2/FactoryProducer.java b/src/main/java/com/shenyy/dp/abstractfactory/exercise2/FactoryProducer.java
new file mode 100644
index 0000000..5ca51d1
--- /dev/null
+++ b/src/main/java/com/shenyy/dp/abstractfactory/exercise2/FactoryProducer.java
@@ -0,0 +1,13 @@
+package com.shenyy.dp.abstractfactory.exercise2;
+
+public class FactoryProducer {
+ public static void main(String[] args) {
+ CarFactory factory = new ChinaFactory();
+ Car car = factory.createLuxury();
+ car.construct();
+
+ CarFactory indiaFactory = new IndiaFactory();
+ Car miniCar = indiaFactory.createMini();
+ miniCar.construct();
+ }
+}
diff --git a/src/main/java/com/shenyy/dp/abstractfactory/exercise2/IndiaFactory.java b/src/main/java/com/shenyy/dp/abstractfactory/exercise2/IndiaFactory.java
new file mode 100644
index 0000000..1e8ff57
--- /dev/null
+++ b/src/main/java/com/shenyy/dp/abstractfactory/exercise2/IndiaFactory.java
@@ -0,0 +1,20 @@
+package com.shenyy.dp.abstractfactory.exercise2;
+
+public class IndiaFactory extends CarFactory {
+ @Override
+ Car createMini() {
+ Car car = new MiniCar(CarType.MINI, Location.INDIA);
+ return car;
+ }
+
+ @Override
+ Car createMicro() {
+ Car car = new MicroCar(CarType.MICRO, Location.INDIA);
+ return car;
+ }
+
+ @Override
+ Car createLuxury() {
+ return null;
+ }
+}
diff --git a/src/main/java/com/shenyy/dp/abstractfactory/exercise2/Location.java b/src/main/java/com/shenyy/dp/abstractfactory/exercise2/Location.java
new file mode 100644
index 0000000..bf504e4
--- /dev/null
+++ b/src/main/java/com/shenyy/dp/abstractfactory/exercise2/Location.java
@@ -0,0 +1,7 @@
+package com.shenyy.dp.abstractfactory.exercise2;
+
+public enum Location {
+ INDIA,
+ CHINA,
+ RUSSIAN
+}
diff --git a/src/main/java/com/shenyy/dp/abstractfactory/exercise2/LuxuryCar.java b/src/main/java/com/shenyy/dp/abstractfactory/exercise2/LuxuryCar.java
new file mode 100644
index 0000000..7722620
--- /dev/null
+++ b/src/main/java/com/shenyy/dp/abstractfactory/exercise2/LuxuryCar.java
@@ -0,0 +1,12 @@
+package com.shenyy.dp.abstractfactory.exercise2;
+
+public class LuxuryCar extends Car {
+ public LuxuryCar(CarType carType, Location location) {
+ super(carType, location);
+ }
+
+ @Override
+ void construct() {
+ System.out.println("Manufacture a " + carType.toString() + " in " + location.toString());
+ }
+}
diff --git a/src/main/java/com/shenyy/dp/abstractfactory/exercise2/MicroCar.java b/src/main/java/com/shenyy/dp/abstractfactory/exercise2/MicroCar.java
new file mode 100644
index 0000000..50fe72f
--- /dev/null
+++ b/src/main/java/com/shenyy/dp/abstractfactory/exercise2/MicroCar.java
@@ -0,0 +1,12 @@
+package com.shenyy.dp.abstractfactory.exercise2;
+
+public class MicroCar extends Car{
+ public MicroCar(CarType carType, Location location) {
+ super(carType, location);
+ }
+
+ @Override
+ void construct() {
+ System.out.println("Manufacture a " + carType.toString() + " in " + location.toString());
+ }
+}
diff --git a/src/main/java/com/shenyy/dp/abstractfactory/exercise2/MiniCar.java b/src/main/java/com/shenyy/dp/abstractfactory/exercise2/MiniCar.java
new file mode 100644
index 0000000..fda0170
--- /dev/null
+++ b/src/main/java/com/shenyy/dp/abstractfactory/exercise2/MiniCar.java
@@ -0,0 +1,12 @@
+package com.shenyy.dp.abstractfactory.exercise2;
+
+public class MiniCar extends Car {
+ public MiniCar(CarType carType, Location location) {
+ super(carType, location);
+ }
+
+ @Override
+ void construct() {
+ System.out.println("Manufacture a " + carType.toString() + " in " + location.toString());
+ }
+}
diff --git a/src/main/java/com/shenyy/dp/adapter/chatgpt/Adaptee.java b/src/main/java/com/shenyy/dp/adapter/chatgpt/Adaptee.java
new file mode 100644
index 0000000..85aa603
--- /dev/null
+++ b/src/main/java/com/shenyy/dp/adapter/chatgpt/Adaptee.java
@@ -0,0 +1,7 @@
+package com.shenyy.dp.adapter.chatgpt;
+
+public class Adaptee {
+ public void specificRequest(){
+ System.out.println("Specific Request");
+ }
+}
diff --git a/src/main/java/com/shenyy/dp/adapter/chatgpt/Adapter.java b/src/main/java/com/shenyy/dp/adapter/chatgpt/Adapter.java
new file mode 100644
index 0000000..ba9c0be
--- /dev/null
+++ b/src/main/java/com/shenyy/dp/adapter/chatgpt/Adapter.java
@@ -0,0 +1,14 @@
+package com.shenyy.dp.adapter.chatgpt;
+
+public class Adapter implements Target{
+ private Adaptee adaptee;
+
+ public Adapter(Adaptee adaptee) {
+ this.adaptee = adaptee;
+ }
+
+ @Override
+ public void request() {
+ adaptee.specificRequest();
+ }
+}
diff --git a/src/main/java/com/shenyy/dp/adapter/chatgpt/AdapterExample.java b/src/main/java/com/shenyy/dp/adapter/chatgpt/AdapterExample.java
new file mode 100644
index 0000000..9dffa6f
--- /dev/null
+++ b/src/main/java/com/shenyy/dp/adapter/chatgpt/AdapterExample.java
@@ -0,0 +1,10 @@
+package com.shenyy.dp.adapter.chatgpt;
+
+public class AdapterExample {
+ public static void main(String[] args) {
+ Adaptee adaptee = new Adaptee();
+ Target target = new Adapter(adaptee);
+
+ target.request();
+ }
+}
diff --git a/src/main/java/com/shenyy/dp/adapter/chatgpt/Description.md b/src/main/java/com/shenyy/dp/adapter/chatgpt/Description.md
new file mode 100644
index 0000000..a5d85df
--- /dev/null
+++ b/src/main/java/com/shenyy/dp/adapter/chatgpt/Description.md
@@ -0,0 +1,5 @@
+##Description
+
+Adapter pattern is a structural design pattern in software development that allows two incompatible classes to work together by converting the interface of one class into an interface that the other class can understand. The adapter class acts as a bridge between two classes by converting the incoming request from the client into a format that the adapted class can understand, and vice versa.
+
+In this example, the Adaptee class has a specific request method that the client wants to use. The Target interface defines the request method that the client needs. The Adapter class implements the Target interface and has a reference to an instance of the Adaptee class. The Adapter class implements the request method by calling the specificRequest method of the Adaptee class, making it possible for the client to use the Adaptee class through the Target interface.
\ No newline at end of file
diff --git a/src/main/java/com/shenyy/dp/adapter/chatgpt/Target.java b/src/main/java/com/shenyy/dp/adapter/chatgpt/Target.java
new file mode 100644
index 0000000..2175abe
--- /dev/null
+++ b/src/main/java/com/shenyy/dp/adapter/chatgpt/Target.java
@@ -0,0 +1,5 @@
+package com.shenyy.dp.adapter.chatgpt;
+
+public interface Target {
+ void request();
+}
diff --git a/src/main/java/com/mashibing/dp/adapter/Main.java b/src/main/java/com/shenyy/dp/adapter/example01/Main.java
similarity index 92%
rename from src/main/java/com/mashibing/dp/adapter/Main.java
rename to src/main/java/com/shenyy/dp/adapter/example01/Main.java
index 021eca6..e516c46 100644
--- a/src/main/java/com/mashibing/dp/adapter/Main.java
+++ b/src/main/java/com/shenyy/dp/adapter/example01/Main.java
@@ -1,4 +1,4 @@
-package com.mashibing.dp.adapter;
+package com.shenyy.dp.adapter.example01;
import java.io.BufferedReader;
import java.io.FileInputStream;
diff --git a/src/main/java/com/shenyy/dp/adapter/exercise/ApiAdapter.java b/src/main/java/com/shenyy/dp/adapter/exercise/ApiAdapter.java
new file mode 100644
index 0000000..3754853
--- /dev/null
+++ b/src/main/java/com/shenyy/dp/adapter/exercise/ApiAdapter.java
@@ -0,0 +1,19 @@
+package com.shenyy.dp.adapter.exercise;
+
+public class ApiAdapter implements TargetApi{
+ public static void main(String[] args) {
+ TargetApi adapter = new ApiAdapter(new UserApi());
+ adapter.postRequest();
+ }
+
+ UserApi userApi;
+
+ public ApiAdapter(UserApi userApi) {
+ this.userApi = userApi;
+ }
+
+ @Override
+ public void postRequest() {
+ userApi.getRequest();
+ }
+}
diff --git a/src/main/java/com/shenyy/dp/adapter/exercise/TargetApi.java b/src/main/java/com/shenyy/dp/adapter/exercise/TargetApi.java
new file mode 100644
index 0000000..189d98c
--- /dev/null
+++ b/src/main/java/com/shenyy/dp/adapter/exercise/TargetApi.java
@@ -0,0 +1,5 @@
+package com.shenyy.dp.adapter.exercise;
+
+public interface TargetApi {
+ public void postRequest();
+}
diff --git a/src/main/java/com/shenyy/dp/adapter/exercise/UserApi.java b/src/main/java/com/shenyy/dp/adapter/exercise/UserApi.java
new file mode 100644
index 0000000..4d5e380
--- /dev/null
+++ b/src/main/java/com/shenyy/dp/adapter/exercise/UserApi.java
@@ -0,0 +1,7 @@
+package com.shenyy.dp.adapter.exercise;
+
+public class UserApi {
+ public void getRequest() {
+ System.out.println("Get Request");
+ }
+}
diff --git a/src/main/java/com/shenyy/dp/bridge/Description.md b/src/main/java/com/shenyy/dp/bridge/Description.md
new file mode 100644
index 0000000..d404511
--- /dev/null
+++ b/src/main/java/com/shenyy/dp/bridge/Description.md
@@ -0,0 +1,49 @@
+##Description
+
+The Bridge design pattern allows you to separate the abstraction from the implementation. It is a structural design pattern.
+
+**There are 2 parts in Bridge design pattern :**
+
+1. Abstraction
+2. Implementation
+
+This is a design mechanism that encapsulates an implementation class inside an interface class.
+
+* The bridge pattern allows the Abstraction, and the Implementation to be developed independently and the client code can access only the Abstraction part without being concerned about the Implementation part.
+* The abstraction is an interface or abstract class, and the implementer is also an interface or abstract class.
+* The abstraction contains a reference to the implementer. Children of the abstraction are referred to as refined abstractions, and children of the implementer are concrete implementers. Since we can change the reference to the implementer in the abstraction, we are able to change the abstraction’s implementer at run-time. Changes to the implementer do not affect client code.
+* It increases the loose coupling between class abstraction, and it’s implementation.
+
+##UML Diagram of Bridge Design Pattern
+
+
+
+##Elements of Bridge Design Pattern
+
+* **Abstraction** – core of the bridge design pattern and defines the crux. Contains a reference to the implementer.
+* **Refined Abstraction** – Extends the abstraction takes the finer detail one level below. Hides the finer elements from implementers.
+* **Implementer** – It defines the interface for implementation classes. This interface does not need to correspond directly to the abstraction interface and can be very different. Abstraction imp provides an implementation in terms of operations provided by the Implementer interface.
+* **Concrete** Implementation – Implements the above implementer by providing the concrete implementation.
+
+##When we need bridge design pattern
+
+The Bridge pattern is an application of the old advice, “prefer composition over inheritance”. It becomes handy when you must subclass different times in ways that are orthogonal with one another.
+
+##Without Bridge Design Pattern
+
+But the above solution has a problem. If you want to change the Bus class, then you may end up changing ProduceBus and AssembleBus as well and if the change is workshop specific then you may need to change the Bike class as well.
+
+
+##With Bridge Design Pattern
+
+You can solve the above problem by decoupling the Vehicle and Workshop interfaces in the below manner.
+
+
+##Advantages
+1. Bridge pattern decouple an abstraction from its implementation so that the two can vary independently.
+2. It is used mainly for implementing platform independence features.
+3. It adds one more method level redirection to achieve the objective.
+4. Publish abstraction interface in a separate inheritance hierarchy, and put the implementation in its own inheritance hierarchy.
+5. Use bridge pattern to run-time binding of the implementation.
+6. Use bridge pattern to map orthogonal class hierarchies
+7. Bridge is designed up-front to let the abstraction and the implementation vary independently.
\ No newline at end of file
diff --git a/src/main/java/com/shenyy/dp/bridge/assets/BridgeDesign3.png b/src/main/java/com/shenyy/dp/bridge/assets/BridgeDesign3.png
new file mode 100644
index 0000000..04683f2
Binary files /dev/null and b/src/main/java/com/shenyy/dp/bridge/assets/BridgeDesign3.png differ
diff --git a/src/main/java/com/shenyy/dp/bridge/assets/Bridge_Design.png b/src/main/java/com/shenyy/dp/bridge/assets/Bridge_Design.png
new file mode 100644
index 0000000..483fc08
Binary files /dev/null and b/src/main/java/com/shenyy/dp/bridge/assets/Bridge_Design.png differ
diff --git a/src/main/java/com/shenyy/dp/bridge/assets/im2.png b/src/main/java/com/shenyy/dp/bridge/assets/im2.png
new file mode 100644
index 0000000..9dcdb78
Binary files /dev/null and b/src/main/java/com/shenyy/dp/bridge/assets/im2.png differ
diff --git a/src/main/java/com/shenyy/dp/bridge/chatgpt/BridgeExample.java b/src/main/java/com/shenyy/dp/bridge/chatgpt/BridgeExample.java
new file mode 100644
index 0000000..9c7d4f6
--- /dev/null
+++ b/src/main/java/com/shenyy/dp/bridge/chatgpt/BridgeExample.java
@@ -0,0 +1,12 @@
+package com.shenyy.dp.bridge.chatgpt;
+
+public class BridgeExample {
+ public static void main(String[] args) {
+ Shape circle = new Circle(new Red());
+ circle.applyColor();
+
+ Shape triangle = new Triangle(new Green());
+ triangle.applyColor();
+ System.out.println("");
+ }
+}
diff --git a/src/main/java/com/shenyy/dp/bridge/chatgpt/Circle.java b/src/main/java/com/shenyy/dp/bridge/chatgpt/Circle.java
new file mode 100644
index 0000000..2479970
--- /dev/null
+++ b/src/main/java/com/shenyy/dp/bridge/chatgpt/Circle.java
@@ -0,0 +1,14 @@
+package com.shenyy.dp.bridge.chatgpt;
+
+public class Circle extends Shape{
+
+ public Circle(Color color) {
+ super(color);
+ }
+
+ @Override
+ public void applyColor() {
+ System.out.print("Circle filled with color ");
+ color.applyColor();
+ }
+}
diff --git a/src/main/java/com/shenyy/dp/bridge/chatgpt/Color.java b/src/main/java/com/shenyy/dp/bridge/chatgpt/Color.java
new file mode 100644
index 0000000..94ecf49
--- /dev/null
+++ b/src/main/java/com/shenyy/dp/bridge/chatgpt/Color.java
@@ -0,0 +1,5 @@
+package com.shenyy.dp.bridge.chatgpt;
+
+public interface Color {
+ public void applyColor();
+}
diff --git a/src/main/java/com/shenyy/dp/bridge/chatgpt/Green.java b/src/main/java/com/shenyy/dp/bridge/chatgpt/Green.java
new file mode 100644
index 0000000..5125579
--- /dev/null
+++ b/src/main/java/com/shenyy/dp/bridge/chatgpt/Green.java
@@ -0,0 +1,8 @@
+package com.shenyy.dp.bridge.chatgpt;
+
+public class Green implements Color{
+ @Override
+ public void applyColor() {
+ System.out.println("green.");
+ }
+}
diff --git a/src/main/java/com/shenyy/dp/bridge/chatgpt/Red.java b/src/main/java/com/shenyy/dp/bridge/chatgpt/Red.java
new file mode 100644
index 0000000..05e155d
--- /dev/null
+++ b/src/main/java/com/shenyy/dp/bridge/chatgpt/Red.java
@@ -0,0 +1,8 @@
+package com.shenyy.dp.bridge.chatgpt;
+
+public class Red implements Color{
+ @Override
+ public void applyColor() {
+ System.out.println("red.");
+ }
+}
diff --git a/src/main/java/com/shenyy/dp/bridge/chatgpt/Shape.java b/src/main/java/com/shenyy/dp/bridge/chatgpt/Shape.java
new file mode 100644
index 0000000..2ed6ab0
--- /dev/null
+++ b/src/main/java/com/shenyy/dp/bridge/chatgpt/Shape.java
@@ -0,0 +1,11 @@
+package com.shenyy.dp.bridge.chatgpt;
+
+abstract class Shape {
+ protected Color color;
+
+ public Shape(Color color) {
+ this.color = color;
+ }
+
+ public abstract void applyColor();
+}
diff --git a/src/main/java/com/shenyy/dp/bridge/chatgpt/Triangle.java b/src/main/java/com/shenyy/dp/bridge/chatgpt/Triangle.java
new file mode 100644
index 0000000..15c2620
--- /dev/null
+++ b/src/main/java/com/shenyy/dp/bridge/chatgpt/Triangle.java
@@ -0,0 +1,13 @@
+package com.shenyy.dp.bridge.chatgpt;
+
+public class Triangle extends Shape {
+ public Triangle(Color color) {
+ super(color);
+ }
+
+ @Override
+ public void applyColor() {
+ System.out.print("Triangle filled with color ");
+ color.applyColor();
+ }
+}
diff --git a/src/main/java/com/shenyy/dp/bridge/example01/v1/Book.java b/src/main/java/com/shenyy/dp/bridge/example01/v1/Book.java
new file mode 100644
index 0000000..2a2812b
--- /dev/null
+++ b/src/main/java/com/shenyy/dp/bridge/example01/v1/Book.java
@@ -0,0 +1,4 @@
+package com.shenyy.dp.bridge.example01.v1;
+
+public class Book extends Gift {
+}
diff --git a/src/main/java/com/shenyy/dp/bridge/example01/v1/Flower.java b/src/main/java/com/shenyy/dp/bridge/example01/v1/Flower.java
new file mode 100644
index 0000000..fdf0183
--- /dev/null
+++ b/src/main/java/com/shenyy/dp/bridge/example01/v1/Flower.java
@@ -0,0 +1,4 @@
+package com.shenyy.dp.bridge.example01.v1;
+
+public class Flower extends Gift {
+}
diff --git a/src/main/java/com/mashibing/dp/bridge/v3/GG.java b/src/main/java/com/shenyy/dp/bridge/example01/v1/GG.java
similarity index 78%
rename from src/main/java/com/mashibing/dp/bridge/v3/GG.java
rename to src/main/java/com/shenyy/dp/bridge/example01/v1/GG.java
index f4663d3..80c930f 100644
--- a/src/main/java/com/mashibing/dp/bridge/v3/GG.java
+++ b/src/main/java/com/shenyy/dp/bridge/example01/v1/GG.java
@@ -1,4 +1,4 @@
-package com.mashibing.dp.bridge.v3;
+package com.shenyy.dp.bridge.example01.v1;
public class GG {
public void chase(MM mm) {
diff --git a/src/main/java/com/shenyy/dp/bridge/example01/v1/Gift.java b/src/main/java/com/shenyy/dp/bridge/example01/v1/Gift.java
new file mode 100644
index 0000000..4f4b6ac
--- /dev/null
+++ b/src/main/java/com/shenyy/dp/bridge/example01/v1/Gift.java
@@ -0,0 +1,3 @@
+package com.shenyy.dp.bridge.example01.v1;
+
+public abstract class Gift {}
diff --git a/src/main/java/com/shenyy/dp/bridge/example01/v1/MM.java b/src/main/java/com/shenyy/dp/bridge/example01/v1/MM.java
new file mode 100644
index 0000000..0038172
--- /dev/null
+++ b/src/main/java/com/shenyy/dp/bridge/example01/v1/MM.java
@@ -0,0 +1,5 @@
+package com.shenyy.dp.bridge.example01.v1;
+
+public class MM {
+ String name;
+}
diff --git a/src/main/java/com/shenyy/dp/bridge/example01/v2/Book.java b/src/main/java/com/shenyy/dp/bridge/example01/v2/Book.java
new file mode 100644
index 0000000..1bc3b58
--- /dev/null
+++ b/src/main/java/com/shenyy/dp/bridge/example01/v2/Book.java
@@ -0,0 +1,4 @@
+package com.shenyy.dp.bridge.example01.v2;
+
+public class Book extends Gift {
+}
diff --git a/src/main/java/com/shenyy/dp/bridge/example01/v2/Flower.java b/src/main/java/com/shenyy/dp/bridge/example01/v2/Flower.java
new file mode 100644
index 0000000..e5f411e
--- /dev/null
+++ b/src/main/java/com/shenyy/dp/bridge/example01/v2/Flower.java
@@ -0,0 +1,4 @@
+package com.shenyy.dp.bridge.example01.v2;
+
+public class Flower extends Gift {
+}
diff --git a/src/main/java/com/mashibing/dp/bridge/v1/GG.java b/src/main/java/com/shenyy/dp/bridge/example01/v2/GG.java
similarity index 78%
rename from src/main/java/com/mashibing/dp/bridge/v1/GG.java
rename to src/main/java/com/shenyy/dp/bridge/example01/v2/GG.java
index b2d09a3..fece11f 100644
--- a/src/main/java/com/mashibing/dp/bridge/v1/GG.java
+++ b/src/main/java/com/shenyy/dp/bridge/example01/v2/GG.java
@@ -1,4 +1,4 @@
-package com.mashibing.dp.bridge.v1;
+package com.shenyy.dp.bridge.example01.v2;
public class GG {
public void chase(MM mm) {
diff --git a/src/main/java/com/shenyy/dp/bridge/example01/v2/Gift.java b/src/main/java/com/shenyy/dp/bridge/example01/v2/Gift.java
new file mode 100644
index 0000000..7afefb6
--- /dev/null
+++ b/src/main/java/com/shenyy/dp/bridge/example01/v2/Gift.java
@@ -0,0 +1,3 @@
+package com.shenyy.dp.bridge.example01.v2;
+
+public abstract class Gift {}
diff --git a/src/main/java/com/shenyy/dp/bridge/example01/v2/MM.java b/src/main/java/com/shenyy/dp/bridge/example01/v2/MM.java
new file mode 100644
index 0000000..6c9e516
--- /dev/null
+++ b/src/main/java/com/shenyy/dp/bridge/example01/v2/MM.java
@@ -0,0 +1,5 @@
+package com.shenyy.dp.bridge.example01.v2;
+
+public class MM {
+ String name;
+}
diff --git a/src/main/java/com/shenyy/dp/bridge/example01/v2/WarmGift.java b/src/main/java/com/shenyy/dp/bridge/example01/v2/WarmGift.java
new file mode 100644
index 0000000..8268f22
--- /dev/null
+++ b/src/main/java/com/shenyy/dp/bridge/example01/v2/WarmGift.java
@@ -0,0 +1,4 @@
+package com.shenyy.dp.bridge.example01.v2;
+
+public class WarmGift extends Gift {
+}
diff --git a/src/main/java/com/shenyy/dp/bridge/example01/v2/WildGift.java b/src/main/java/com/shenyy/dp/bridge/example01/v2/WildGift.java
new file mode 100644
index 0000000..3d761e6
--- /dev/null
+++ b/src/main/java/com/shenyy/dp/bridge/example01/v2/WildGift.java
@@ -0,0 +1,4 @@
+package com.shenyy.dp.bridge.example01.v2;
+
+public class WildGift extends Gift {
+}
diff --git a/src/main/java/com/mashibing/dp/bridge/v2/readme b/src/main/java/com/shenyy/dp/bridge/example01/v2/readme
similarity index 100%
rename from src/main/java/com/mashibing/dp/bridge/v2/readme
rename to src/main/java/com/shenyy/dp/bridge/example01/v2/readme
diff --git a/src/main/java/com/shenyy/dp/bridge/example01/v3/Book.java b/src/main/java/com/shenyy/dp/bridge/example01/v3/Book.java
new file mode 100644
index 0000000..fe231ad
--- /dev/null
+++ b/src/main/java/com/shenyy/dp/bridge/example01/v3/Book.java
@@ -0,0 +1,4 @@
+package com.shenyy.dp.bridge.example01.v3;
+
+public class Book extends Gift {
+}
diff --git a/src/main/java/com/shenyy/dp/bridge/example01/v3/Flower.java b/src/main/java/com/shenyy/dp/bridge/example01/v3/Flower.java
new file mode 100644
index 0000000..54bfc9e
--- /dev/null
+++ b/src/main/java/com/shenyy/dp/bridge/example01/v3/Flower.java
@@ -0,0 +1,4 @@
+package com.shenyy.dp.bridge.example01.v3;
+
+public class Flower extends Gift {
+}
diff --git a/src/main/java/com/mashibing/dp/bridge/v2/GG.java b/src/main/java/com/shenyy/dp/bridge/example01/v3/GG.java
similarity index 78%
rename from src/main/java/com/mashibing/dp/bridge/v2/GG.java
rename to src/main/java/com/shenyy/dp/bridge/example01/v3/GG.java
index 1ccbcf0..32e148f 100644
--- a/src/main/java/com/mashibing/dp/bridge/v2/GG.java
+++ b/src/main/java/com/shenyy/dp/bridge/example01/v3/GG.java
@@ -1,4 +1,4 @@
-package com.mashibing.dp.bridge.v2;
+package com.shenyy.dp.bridge.example01.v3;
public class GG {
public void chase(MM mm) {
diff --git a/src/main/java/com/shenyy/dp/bridge/example01/v3/Gift.java b/src/main/java/com/shenyy/dp/bridge/example01/v3/Gift.java
new file mode 100644
index 0000000..c0cddad
--- /dev/null
+++ b/src/main/java/com/shenyy/dp/bridge/example01/v3/Gift.java
@@ -0,0 +1,3 @@
+package com.shenyy.dp.bridge.example01.v3;
+
+public abstract class Gift {}
diff --git a/src/main/java/com/shenyy/dp/bridge/example01/v3/MM.java b/src/main/java/com/shenyy/dp/bridge/example01/v3/MM.java
new file mode 100644
index 0000000..d0945ed
--- /dev/null
+++ b/src/main/java/com/shenyy/dp/bridge/example01/v3/MM.java
@@ -0,0 +1,5 @@
+package com.shenyy.dp.bridge.example01.v3;
+
+public class MM {
+ String name;
+}
diff --git a/src/main/java/com/mashibing/dp/bridge/v3/WarmFlower.java b/src/main/java/com/shenyy/dp/bridge/example01/v3/WarmFlower.java
similarity index 70%
rename from src/main/java/com/mashibing/dp/bridge/v3/WarmFlower.java
rename to src/main/java/com/shenyy/dp/bridge/example01/v3/WarmFlower.java
index f0ca1d0..4ee0ec1 100644
--- a/src/main/java/com/mashibing/dp/bridge/v3/WarmFlower.java
+++ b/src/main/java/com/shenyy/dp/bridge/example01/v3/WarmFlower.java
@@ -1,4 +1,4 @@
-package com.mashibing.dp.bridge.v3;
+package com.shenyy.dp.bridge.example01.v3;
/**
* 或者从WarmGift继承
diff --git a/src/main/java/com/shenyy/dp/bridge/example01/v3/WarmGift.java b/src/main/java/com/shenyy/dp/bridge/example01/v3/WarmGift.java
new file mode 100644
index 0000000..40481fd
--- /dev/null
+++ b/src/main/java/com/shenyy/dp/bridge/example01/v3/WarmGift.java
@@ -0,0 +1,4 @@
+package com.shenyy.dp.bridge.example01.v3;
+
+public class WarmGift extends Gift {
+}
diff --git a/src/main/java/com/shenyy/dp/bridge/example01/v3/WildGift.java b/src/main/java/com/shenyy/dp/bridge/example01/v3/WildGift.java
new file mode 100644
index 0000000..62a1b99
--- /dev/null
+++ b/src/main/java/com/shenyy/dp/bridge/example01/v3/WildGift.java
@@ -0,0 +1,4 @@
+package com.shenyy.dp.bridge.example01.v3;
+
+public class WildGift extends Gift {
+}
diff --git a/src/main/java/com/mashibing/dp/bridge/v3/readme b/src/main/java/com/shenyy/dp/bridge/example01/v3/readme
similarity index 100%
rename from src/main/java/com/mashibing/dp/bridge/v3/readme
rename to src/main/java/com/shenyy/dp/bridge/example01/v3/readme
diff --git a/src/main/java/com/shenyy/dp/bridge/example01/v4/Book.java b/src/main/java/com/shenyy/dp/bridge/example01/v4/Book.java
new file mode 100644
index 0000000..480b312
--- /dev/null
+++ b/src/main/java/com/shenyy/dp/bridge/example01/v4/Book.java
@@ -0,0 +1,4 @@
+package com.shenyy.dp.bridge.example01.v4;
+
+public class Book extends GiftImpl {
+}
diff --git a/src/main/java/com/shenyy/dp/bridge/example01/v4/Flower.java b/src/main/java/com/shenyy/dp/bridge/example01/v4/Flower.java
new file mode 100644
index 0000000..1cfac9c
--- /dev/null
+++ b/src/main/java/com/shenyy/dp/bridge/example01/v4/Flower.java
@@ -0,0 +1,4 @@
+package com.shenyy.dp.bridge.example01.v4;
+
+public class Flower extends GiftImpl {
+}
diff --git a/src/main/java/com/mashibing/dp/bridge/v4/GG.java b/src/main/java/com/shenyy/dp/bridge/example01/v4/GG.java
similarity index 83%
rename from src/main/java/com/mashibing/dp/bridge/v4/GG.java
rename to src/main/java/com/shenyy/dp/bridge/example01/v4/GG.java
index df5f3f9..d89f6a5 100644
--- a/src/main/java/com/mashibing/dp/bridge/v4/GG.java
+++ b/src/main/java/com/shenyy/dp/bridge/example01/v4/GG.java
@@ -1,4 +1,4 @@
-package com.mashibing.dp.bridge.v4;
+package com.shenyy.dp.bridge.example01.v4;
public class GG {
public void chase(MM mm) {
diff --git a/src/main/java/com/mashibing/dp/bridge/v4/Gift.java b/src/main/java/com/shenyy/dp/bridge/example01/v4/Gift.java
similarity index 54%
rename from src/main/java/com/mashibing/dp/bridge/v4/Gift.java
rename to src/main/java/com/shenyy/dp/bridge/example01/v4/Gift.java
index fc39ba6..01a9153 100644
--- a/src/main/java/com/mashibing/dp/bridge/v4/Gift.java
+++ b/src/main/java/com/shenyy/dp/bridge/example01/v4/Gift.java
@@ -1,4 +1,4 @@
-package com.mashibing.dp.bridge.v4;
+package com.shenyy.dp.bridge.example01.v4;
public abstract class Gift {
GiftImpl impl;
diff --git a/src/main/java/com/shenyy/dp/bridge/example01/v4/GiftImpl.java b/src/main/java/com/shenyy/dp/bridge/example01/v4/GiftImpl.java
new file mode 100644
index 0000000..b2133fb
--- /dev/null
+++ b/src/main/java/com/shenyy/dp/bridge/example01/v4/GiftImpl.java
@@ -0,0 +1,4 @@
+package com.shenyy.dp.bridge.example01.v4;
+
+public class GiftImpl {
+}
diff --git a/src/main/java/com/shenyy/dp/bridge/example01/v4/MM.java b/src/main/java/com/shenyy/dp/bridge/example01/v4/MM.java
new file mode 100644
index 0000000..db0c145
--- /dev/null
+++ b/src/main/java/com/shenyy/dp/bridge/example01/v4/MM.java
@@ -0,0 +1,5 @@
+package com.shenyy.dp.bridge.example01.v4;
+
+public class MM {
+ String name;
+}
diff --git a/src/main/java/com/mashibing/dp/bridge/v4/WarmGift.java b/src/main/java/com/shenyy/dp/bridge/example01/v4/WarmGift.java
similarity index 71%
rename from src/main/java/com/mashibing/dp/bridge/v4/WarmGift.java
rename to src/main/java/com/shenyy/dp/bridge/example01/v4/WarmGift.java
index ebebd12..5230089 100644
--- a/src/main/java/com/mashibing/dp/bridge/v4/WarmGift.java
+++ b/src/main/java/com/shenyy/dp/bridge/example01/v4/WarmGift.java
@@ -1,4 +1,4 @@
-package com.mashibing.dp.bridge.v4;
+package com.shenyy.dp.bridge.example01.v4;
public class WarmGift extends Gift {
public WarmGift(GiftImpl impl) {
diff --git a/src/main/java/com/mashibing/dp/bridge/v4/WildGift.java b/src/main/java/com/shenyy/dp/bridge/example01/v4/WildGift.java
similarity index 71%
rename from src/main/java/com/mashibing/dp/bridge/v4/WildGift.java
rename to src/main/java/com/shenyy/dp/bridge/example01/v4/WildGift.java
index 123e955..067077f 100644
--- a/src/main/java/com/mashibing/dp/bridge/v4/WildGift.java
+++ b/src/main/java/com/shenyy/dp/bridge/example01/v4/WildGift.java
@@ -1,4 +1,4 @@
-package com.mashibing.dp.bridge.v4;
+package com.shenyy.dp.bridge.example01.v4;
public class WildGift extends Gift {
public WildGift(GiftImpl impl) {
diff --git a/src/main/java/com/mashibing/dp/bridge/v4/readme b/src/main/java/com/shenyy/dp/bridge/example01/v4/readme
similarity index 100%
rename from src/main/java/com/mashibing/dp/bridge/v4/readme
rename to src/main/java/com/shenyy/dp/bridge/example01/v4/readme
diff --git a/src/main/java/com/shenyy/dp/bridge/exercise/Assemble.java b/src/main/java/com/shenyy/dp/bridge/exercise/Assemble.java
new file mode 100644
index 0000000..4651444
--- /dev/null
+++ b/src/main/java/com/shenyy/dp/bridge/exercise/Assemble.java
@@ -0,0 +1,8 @@
+package com.shenyy.dp.bridge.exercise;
+
+public class Assemble implements Workshop{
+ @Override
+ public void work() {
+ System.out.println(" And Assembled.");
+ }
+}
diff --git a/src/main/java/com/shenyy/dp/bridge/exercise/BridgeExample.java b/src/main/java/com/shenyy/dp/bridge/exercise/BridgeExample.java
new file mode 100644
index 0000000..276f47a
--- /dev/null
+++ b/src/main/java/com/shenyy/dp/bridge/exercise/BridgeExample.java
@@ -0,0 +1,8 @@
+package com.shenyy.dp.bridge.exercise;
+
+public class BridgeExample {
+ public static void main(String[] args) {
+ Vehicle vehicle1 = new Car(new Produce(),new Assemble());
+ vehicle1.manufacture();
+ }
+}
diff --git a/src/main/java/com/shenyy/dp/bridge/exercise/Car.java b/src/main/java/com/shenyy/dp/bridge/exercise/Car.java
new file mode 100644
index 0000000..bee87ce
--- /dev/null
+++ b/src/main/java/com/shenyy/dp/bridge/exercise/Car.java
@@ -0,0 +1,14 @@
+package com.shenyy.dp.bridge.exercise;
+
+public class Car extends Vehicle{
+ public Car(Workshop workshop1, Workshop workshop2) {
+ super(workshop1, workshop2);
+ }
+
+ @Override
+ public void manufacture() {
+ System.out.print("Car ");
+ workshop1.work();
+ workshop2.work();
+ }
+}
diff --git a/src/main/java/com/shenyy/dp/bridge/exercise/Produce.java b/src/main/java/com/shenyy/dp/bridge/exercise/Produce.java
new file mode 100644
index 0000000..6f7f808
--- /dev/null
+++ b/src/main/java/com/shenyy/dp/bridge/exercise/Produce.java
@@ -0,0 +1,8 @@
+package com.shenyy.dp.bridge.exercise;
+
+public class Produce implements Workshop {
+ @Override
+ public void work() {
+ System.out.print("Produced");
+ }
+}
diff --git a/src/main/java/com/shenyy/dp/bridge/exercise/Vehicle.java b/src/main/java/com/shenyy/dp/bridge/exercise/Vehicle.java
new file mode 100644
index 0000000..6210ee0
--- /dev/null
+++ b/src/main/java/com/shenyy/dp/bridge/exercise/Vehicle.java
@@ -0,0 +1,13 @@
+package com.shenyy.dp.bridge.exercise;
+
+abstract class Vehicle {
+ protected Workshop workshop1;
+ protected Workshop workshop2;
+
+ public Vehicle(Workshop workshop1, Workshop workshop2) {
+ this.workshop1 = workshop1;
+ this.workshop2 = workshop2;
+ }
+
+ public abstract void manufacture();
+}
diff --git a/src/main/java/com/shenyy/dp/bridge/exercise/Workshop.java b/src/main/java/com/shenyy/dp/bridge/exercise/Workshop.java
new file mode 100644
index 0000000..b810027
--- /dev/null
+++ b/src/main/java/com/shenyy/dp/bridge/exercise/Workshop.java
@@ -0,0 +1,5 @@
+package com.shenyy.dp.bridge.exercise;
+
+public interface Workshop {
+ public void work();
+}
diff --git "a/src/main/java/com/shenyy/dp/builder/chatGPT/ \346\236\204\345\273\272\346\250\241\345\274\217\344\273\213\347\273\215\345\217\212\347\244\272\344\276\213.md" "b/src/main/java/com/shenyy/dp/builder/chatGPT/ \346\236\204\345\273\272\346\250\241\345\274\217\344\273\213\347\273\215\345\217\212\347\244\272\344\276\213.md"
new file mode 100644
index 0000000..d275355
--- /dev/null
+++ "b/src/main/java/com/shenyy/dp/builder/chatGPT/ \346\236\204\345\273\272\346\250\241\345\274\217\344\273\213\347\273\215\345\217\212\347\244\272\344\276\213.md"
@@ -0,0 +1,5 @@
+##构建模式介绍及示例
+
+Builder pattern is a creational design pattern that allows constructing complex objects step by step. The pattern involves a builder object that is used to define the types and amounts of ingredients to be used in a product (such as a burger).
+
+For example, consider a burger restaurant that offers different types of burgers with different ingredients. To build a burger, you may use the following code
\ No newline at end of file
diff --git a/src/main/java/com/shenyy/dp/builder/chatGPT/BuilderExample.java b/src/main/java/com/shenyy/dp/builder/chatGPT/BuilderExample.java
new file mode 100644
index 0000000..97908a9
--- /dev/null
+++ b/src/main/java/com/shenyy/dp/builder/chatGPT/BuilderExample.java
@@ -0,0 +1,15 @@
+package com.shenyy.dp.builder.chatGPT;
+
+public class BuilderExample {
+ public static void main(String[] args) {
+ Burger burger = new Burger.Builder()
+ .meat("chicken")
+ .bread("wheat")
+ .cheese("cheese")
+ .sauce("BBQ")
+ .vegetables(new String[]{"tomato", "onion"})
+ .build();
+
+ System.out.println(burger);
+ }
+}
diff --git a/src/main/java/com/shenyy/dp/builder/chatGPT/Burger.java b/src/main/java/com/shenyy/dp/builder/chatGPT/Burger.java
new file mode 100644
index 0000000..ee6fb0c
--- /dev/null
+++ b/src/main/java/com/shenyy/dp/builder/chatGPT/Burger.java
@@ -0,0 +1,55 @@
+package com.shenyy.dp.builder.chatGPT;
+
+public class Burger {
+ private String bread;
+ private String meat;
+ private String sauce;
+ private String cheese;
+ private String vegetables[];
+
+ public Burger(Builder builder) {
+ this.bread = builder.bread;
+ this.meat = builder.meat;
+ this.sauce = builder.sauce;
+ this.cheese = builder.cheese;
+ this.vegetables = builder.vegetables;
+ }
+
+ public static class Builder {
+ private String bread;
+ private String meat;
+ private String sauce;
+ private String cheese;
+ private String vegetables[];
+
+ public Builder bread(String bread) {
+ this.bread = bread;
+ return this;
+ }
+
+ public Builder meat(String meat) {
+ this.meat = meat;
+ return this;
+ }
+
+ public Builder sauce(String sauce) {
+ this.sauce = sauce;
+ return this;
+ }
+
+ public Builder cheese(String cheese) {
+ this.cheese = cheese;
+ return this;
+ }
+
+ public Builder vegetables(String[] vegetables) {
+ this.vegetables = vegetables;
+ return this;
+ }
+
+ public Burger build() {
+ return new Burger(this);
+ }
+ }
+
+}
diff --git a/src/main/java/com/mashibing/dp/builder/ComplexTerrainBuilder.java b/src/main/java/com/shenyy/dp/builder/example01/ComplexTerrainBuilder.java
similarity index 93%
rename from src/main/java/com/mashibing/dp/builder/ComplexTerrainBuilder.java
rename to src/main/java/com/shenyy/dp/builder/example01/ComplexTerrainBuilder.java
index f308794..d364dd7 100644
--- a/src/main/java/com/mashibing/dp/builder/ComplexTerrainBuilder.java
+++ b/src/main/java/com/shenyy/dp/builder/example01/ComplexTerrainBuilder.java
@@ -1,4 +1,4 @@
-package com.mashibing.dp.builder;
+package com.shenyy.dp.builder.example01;
public class ComplexTerrainBuilder implements TerrainBuilder {
Terrain terrain = new Terrain();
diff --git a/src/main/java/com/mashibing/dp/builder/Main.java b/src/main/java/com/shenyy/dp/builder/example01/Main.java
similarity index 92%
rename from src/main/java/com/mashibing/dp/builder/Main.java
rename to src/main/java/com/shenyy/dp/builder/example01/Main.java
index f282b65..2f9020c 100644
--- a/src/main/java/com/mashibing/dp/builder/Main.java
+++ b/src/main/java/com/shenyy/dp/builder/example01/Main.java
@@ -1,4 +1,4 @@
-package com.mashibing.dp.builder;
+package com.shenyy.dp.builder.example01;
public class Main {
public static void main(String[] args) {
diff --git a/src/main/java/com/mashibing/dp/builder/Person.java b/src/main/java/com/shenyy/dp/builder/example01/Person.java
similarity index 96%
rename from src/main/java/com/mashibing/dp/builder/Person.java
rename to src/main/java/com/shenyy/dp/builder/example01/Person.java
index cc34f53..10cab1c 100644
--- a/src/main/java/com/mashibing/dp/builder/Person.java
+++ b/src/main/java/com/shenyy/dp/builder/example01/Person.java
@@ -1,4 +1,4 @@
-package com.mashibing.dp.builder;
+package com.shenyy.dp.builder.example01;
public class Person {
int id;
diff --git a/src/main/java/com/mashibing/dp/builder/Terrain.java b/src/main/java/com/shenyy/dp/builder/example01/Terrain.java
similarity index 93%
rename from src/main/java/com/mashibing/dp/builder/Terrain.java
rename to src/main/java/com/shenyy/dp/builder/example01/Terrain.java
index d8848d7..26a64f8 100644
--- a/src/main/java/com/mashibing/dp/builder/Terrain.java
+++ b/src/main/java/com/shenyy/dp/builder/example01/Terrain.java
@@ -1,4 +1,4 @@
-package com.mashibing.dp.builder;
+package com.shenyy.dp.builder.example01;
public class Terrain {
Wall w;
diff --git a/src/main/java/com/mashibing/dp/builder/TerrainBuilder.java b/src/main/java/com/shenyy/dp/builder/example01/TerrainBuilder.java
similarity index 78%
rename from src/main/java/com/mashibing/dp/builder/TerrainBuilder.java
rename to src/main/java/com/shenyy/dp/builder/example01/TerrainBuilder.java
index 2e87766..d021393 100644
--- a/src/main/java/com/mashibing/dp/builder/TerrainBuilder.java
+++ b/src/main/java/com/shenyy/dp/builder/example01/TerrainBuilder.java
@@ -1,4 +1,4 @@
-package com.mashibing.dp.builder;
+package com.shenyy.dp.builder.example01;
public interface TerrainBuilder {
TerrainBuilder buildWall();
diff --git a/src/main/java/com/mashibing/dp/cglib/Main.java b/src/main/java/com/shenyy/dp/cglib/Main.java
similarity index 97%
rename from src/main/java/com/mashibing/dp/cglib/Main.java
rename to src/main/java/com/shenyy/dp/cglib/Main.java
index a8a34e7..967fff1 100644
--- a/src/main/java/com/mashibing/dp/cglib/Main.java
+++ b/src/main/java/com/shenyy/dp/cglib/Main.java
@@ -1,4 +1,4 @@
-package com.mashibing.dp.cglib;
+package com.shenyy.dp.cglib;
import net.sf.cglib.proxy.Enhancer;
import net.sf.cglib.proxy.MethodInterceptor;
diff --git a/src/main/java/com/shenyy/dp/command/Description.md b/src/main/java/com/shenyy/dp/command/Description.md
new file mode 100644
index 0000000..c480b6b
--- /dev/null
+++ b/src/main/java/com/shenyy/dp/command/Description.md
@@ -0,0 +1,2 @@
+##Description
+The Command Design Pattern is a behavioral design pattern that turns a request into a standalone object that contains all the information about the request. This pattern is useful when you want to pass requests as method calls to objects without knowing the operation being requested or the receiver of the request.
diff --git a/src/main/java/com/shenyy/dp/command/chatgpt/Command.java b/src/main/java/com/shenyy/dp/command/chatgpt/Command.java
new file mode 100644
index 0000000..07c2133
--- /dev/null
+++ b/src/main/java/com/shenyy/dp/command/chatgpt/Command.java
@@ -0,0 +1,5 @@
+package com.shenyy.dp.command.chatgpt;
+
+public interface Command {
+ void execute();
+}
diff --git a/src/main/java/com/shenyy/dp/command/chatgpt/CommandExample.java b/src/main/java/com/shenyy/dp/command/chatgpt/CommandExample.java
new file mode 100644
index 0000000..d1ec157
--- /dev/null
+++ b/src/main/java/com/shenyy/dp/command/chatgpt/CommandExample.java
@@ -0,0 +1,12 @@
+package com.shenyy.dp.command.chatgpt;
+
+public class CommandExample {
+ public static void main(String[] args) {
+ Light light = new Light();
+ Command command = new TurnOnLightCommand(light);
+
+ RemoteControl remoteControl = new RemoteControl();
+ remoteControl.setCommand(command);
+ remoteControl.pressButton();
+ }
+}
diff --git a/src/main/java/com/shenyy/dp/command/chatgpt/Light.java b/src/main/java/com/shenyy/dp/command/chatgpt/Light.java
new file mode 100644
index 0000000..4ae5d34
--- /dev/null
+++ b/src/main/java/com/shenyy/dp/command/chatgpt/Light.java
@@ -0,0 +1,7 @@
+package com.shenyy.dp.command.chatgpt;
+
+public class Light {
+ public void turnOn(){
+ System.out.println("The light is on");
+ }
+}
diff --git a/src/main/java/com/shenyy/dp/command/chatgpt/RemoteControl.java b/src/main/java/com/shenyy/dp/command/chatgpt/RemoteControl.java
new file mode 100644
index 0000000..c53a8ce
--- /dev/null
+++ b/src/main/java/com/shenyy/dp/command/chatgpt/RemoteControl.java
@@ -0,0 +1,13 @@
+package com.shenyy.dp.command.chatgpt;
+
+public class RemoteControl {
+ private Command command;
+
+ public void setCommand(Command command) {
+ this.command = command;
+ }
+
+ public void pressButton() {
+ command.execute();
+ }
+}
diff --git a/src/main/java/com/shenyy/dp/command/chatgpt/TurnOnLightCommand.java b/src/main/java/com/shenyy/dp/command/chatgpt/TurnOnLightCommand.java
new file mode 100644
index 0000000..5ca9a0f
--- /dev/null
+++ b/src/main/java/com/shenyy/dp/command/chatgpt/TurnOnLightCommand.java
@@ -0,0 +1,14 @@
+package com.shenyy.dp.command.chatgpt;
+
+public class TurnOnLightCommand implements Command{
+ private Light light;
+
+ public TurnOnLightCommand(Light light) {
+ this.light = light;
+ }
+
+ @Override
+ public void execute() {
+ light.turnOn();
+ }
+}
diff --git a/src/main/java/com/mashibing/dp/command/Command.java b/src/main/java/com/shenyy/dp/command/example01/Command.java
similarity index 73%
rename from src/main/java/com/mashibing/dp/command/Command.java
rename to src/main/java/com/shenyy/dp/command/example01/Command.java
index 3273e11..a5709c8 100644
--- a/src/main/java/com/mashibing/dp/command/Command.java
+++ b/src/main/java/com/shenyy/dp/command/example01/Command.java
@@ -1,4 +1,4 @@
-package com.mashibing.dp.command;
+package com.shenyy.dp.command.example01;
public abstract class Command {
public abstract void doit(); //exec run
diff --git a/src/main/java/com/mashibing/dp/command/Content.java b/src/main/java/com/shenyy/dp/command/example01/Content.java
similarity index 60%
rename from src/main/java/com/mashibing/dp/command/Content.java
rename to src/main/java/com/shenyy/dp/command/example01/Content.java
index 12b658a..3dfba67 100644
--- a/src/main/java/com/mashibing/dp/command/Content.java
+++ b/src/main/java/com/shenyy/dp/command/example01/Content.java
@@ -1,4 +1,4 @@
-package com.mashibing.dp.command;
+package com.shenyy.dp.command.example01;
public class Content {
String msg = "hello everybody ";
diff --git a/src/main/java/com/mashibing/dp/command/CopyCommand.java b/src/main/java/com/shenyy/dp/command/example01/CopyCommand.java
similarity index 87%
rename from src/main/java/com/mashibing/dp/command/CopyCommand.java
rename to src/main/java/com/shenyy/dp/command/example01/CopyCommand.java
index dde5656..238c03d 100644
--- a/src/main/java/com/mashibing/dp/command/CopyCommand.java
+++ b/src/main/java/com/shenyy/dp/command/example01/CopyCommand.java
@@ -1,4 +1,4 @@
-package com.mashibing.dp.command;
+package com.shenyy.dp.command.example01;
public class CopyCommand extends Command {
Content c;
diff --git a/src/main/java/com/mashibing/dp/command/DeleteCommand.java b/src/main/java/com/shenyy/dp/command/example01/DeleteCommand.java
similarity index 89%
rename from src/main/java/com/mashibing/dp/command/DeleteCommand.java
rename to src/main/java/com/shenyy/dp/command/example01/DeleteCommand.java
index 6c76d19..e1116e5 100644
--- a/src/main/java/com/mashibing/dp/command/DeleteCommand.java
+++ b/src/main/java/com/shenyy/dp/command/example01/DeleteCommand.java
@@ -1,4 +1,4 @@
-package com.mashibing.dp.command;
+package com.shenyy.dp.command.example01;
public class DeleteCommand extends Command {
Content c;
diff --git a/src/main/java/com/mashibing/dp/command/InsertCommand.java b/src/main/java/com/shenyy/dp/command/example01/InsertCommand.java
similarity index 90%
rename from src/main/java/com/mashibing/dp/command/InsertCommand.java
rename to src/main/java/com/shenyy/dp/command/example01/InsertCommand.java
index c88cf2c..ff77f23 100644
--- a/src/main/java/com/mashibing/dp/command/InsertCommand.java
+++ b/src/main/java/com/shenyy/dp/command/example01/InsertCommand.java
@@ -1,4 +1,4 @@
-package com.mashibing.dp.command;
+package com.shenyy.dp.command.example01;
public class InsertCommand extends Command {
Content c;
diff --git a/src/main/java/com/mashibing/dp/command/Main.java b/src/main/java/com/shenyy/dp/command/example01/Main.java
similarity index 95%
rename from src/main/java/com/mashibing/dp/command/Main.java
rename to src/main/java/com/shenyy/dp/command/example01/Main.java
index 7f5a7a5..d5491b3 100644
--- a/src/main/java/com/mashibing/dp/command/Main.java
+++ b/src/main/java/com/shenyy/dp/command/example01/Main.java
@@ -1,4 +1,4 @@
-package com.mashibing.dp.command;
+package com.shenyy.dp.command.example01;
import java.util.ArrayList;
import java.util.List;
diff --git a/src/main/java/com/shenyy/dp/composite/Description.md b/src/main/java/com/shenyy/dp/composite/Description.md
new file mode 100644
index 0000000..7fecaaf
--- /dev/null
+++ b/src/main/java/com/shenyy/dp/composite/Description.md
@@ -0,0 +1,37 @@
+##Description
+
+Composite pattern is a partitioning design pattern and describes a group of objects that is treated the same way as a single instance of the same type of object. The intent of a composite is to “compose” objects into tree structures to represent part-whole hierarchies. It allows you to have a tree structure and ask each node in the tree structure to perform a task.
+
+* As described by Gof, “Compose objects into tree structure to represent part-whole hierarchies. Composite lets client treat individual objects and compositions of objects uniformly”.
+* When dealing with Tree-structured data, programmers often have to discriminate between a leaf-node and a branch. This makes code more complex, and therefore, error prone. The solution is an interface that allows treating complex and primitive objects uniformly.
+* In object-oriented programming, a composite is an object designed as a composition of one-or-more similar objects, all exhibiting similar functionality. This is known as a “has-a” relationship between objects.
+
+The key concept is that you can manipulate a single instance of the object just as you would manipulate a group of them. The operations you can perform on all the composite objects often have a least common denominator relationship.
+
+**The Composite Pattern has four participants:**
+
+1. Component – Component declares the interface for objects in the composition and for accessing and managing its child components. It also implements default behavior for the interface common to all classes as appropriate.
+2. Leaf – Leaf defines behavior for primitive objects in the composition. It represents leaf objects in the composition.
+3. Composite – Composite stores child components and implements child related operations in the component interface.
+4. Client – Client manipulates the objects in the composition through the component interface.
+
+Client use the component class interface to interact with objects in the composition structure. If recipient is a leaf then request is handled directly. If recipient is a composite, then it usually forwards request to its child components, possibly performing additional operations before and after forwarding.
+
+In an organization, It have general managers and under general managers, there can be managers and under managers there can be developers. Now you can set a tree structure and ask each node to perform common operation like getSalary().
+Composite design pattern treats each node in two ways:
+1) Composite – Composite means it can have other objects below it.
+2) leaf – leaf means it has no objects below it.
+
+
+
+
+
+The above figure shows a typical Composite object structure. As you can see, there can be many children to a single parent i.e. Composite, but only one parent per child.
+
+##When to use Composite Design Pattern?
+
+Composite Pattern should be used when clients need to ignore the difference between compositions of objects and individual objects. If programmers find that they are using multiple objects in the same way, and often have nearly identical code to handle each of them, then composite is a good choice, it is less complex in this situation to treat primitives and composites as homogeneous.
+
+1. Less number of objects reduces the memory usage, and it manages to keep us away from errors related to memory like java.lang.OutOfMemoryError.
+2. Although creating an object in Java is really fast, we can still reduce the execution time of our program by sharing objects.
+
diff --git a/src/main/java/com/shenyy/dp/composite/assets/Composite-Design-Pattern-Diagram-1.png b/src/main/java/com/shenyy/dp/composite/assets/Composite-Design-Pattern-Diagram-1.png
new file mode 100644
index 0000000..d0dc85a
Binary files /dev/null and b/src/main/java/com/shenyy/dp/composite/assets/Composite-Design-Pattern-Diagram-1.png differ
diff --git a/src/main/java/com/shenyy/dp/composite/assets/Composite-Design-Pattern-Diagram.png b/src/main/java/com/shenyy/dp/composite/assets/Composite-Design-Pattern-Diagram.png
new file mode 100644
index 0000000..70f6fa9
Binary files /dev/null and b/src/main/java/com/shenyy/dp/composite/assets/Composite-Design-Pattern-Diagram.png differ
diff --git a/src/main/java/com/shenyy/dp/composite/chatgpt/Component.java b/src/main/java/com/shenyy/dp/composite/chatgpt/Component.java
new file mode 100644
index 0000000..4bbd240
--- /dev/null
+++ b/src/main/java/com/shenyy/dp/composite/chatgpt/Component.java
@@ -0,0 +1,5 @@
+package com.shenyy.dp.composite.chatgpt;
+
+public interface Component {
+ void operation();
+}
diff --git a/src/main/java/com/shenyy/dp/composite/chatgpt/Composite.java b/src/main/java/com/shenyy/dp/composite/chatgpt/Composite.java
new file mode 100644
index 0000000..442ae8c
--- /dev/null
+++ b/src/main/java/com/shenyy/dp/composite/chatgpt/Composite.java
@@ -0,0 +1,23 @@
+package com.shenyy.dp.composite.chatgpt;
+
+import java.util.ArrayList;
+import java.util.List;
+
+public class Composite implements Component {
+ private List children = new ArrayList<>();
+
+ public void add(Component component) {
+ children.add(component);
+ }
+
+ public void remove(Component component) {
+ children.remove(component);
+ }
+
+ @Override
+ public void operation() {
+ for (Component child : children) {
+ child.operation();
+ }
+ }
+}
diff --git a/src/main/java/com/shenyy/dp/composite/chatgpt/CompositeExample.java b/src/main/java/com/shenyy/dp/composite/chatgpt/CompositeExample.java
new file mode 100644
index 0000000..5a80b17
--- /dev/null
+++ b/src/main/java/com/shenyy/dp/composite/chatgpt/CompositeExample.java
@@ -0,0 +1,16 @@
+package com.shenyy.dp.composite.chatgpt;
+
+public class CompositeExample {
+ public static void main(String[] args) {
+ Component leaf1 = new Leaf("leaf1");
+ Component leaf2 = new Leaf("leaf2");
+ Composite composite = new Composite();
+ composite.add(leaf1);
+ composite.add(leaf2);
+ Composite composite1 = new Composite();
+ composite1.add(composite);
+ Component leaf3 = new Leaf("leaf3");
+ composite1.add(leaf3);
+ composite1.operation();
+ }
+}
diff --git a/src/main/java/com/shenyy/dp/composite/chatgpt/Leaf.java b/src/main/java/com/shenyy/dp/composite/chatgpt/Leaf.java
new file mode 100644
index 0000000..f880a70
--- /dev/null
+++ b/src/main/java/com/shenyy/dp/composite/chatgpt/Leaf.java
@@ -0,0 +1,14 @@
+package com.shenyy.dp.composite.chatgpt;
+
+public class Leaf implements Component {
+ private String name;
+
+ public Leaf(String name) {
+ this.name = name;
+ }
+
+ @Override
+ public void operation() {
+ System.out.println(name);
+ }
+}
diff --git a/src/main/java/com/mashibing/dp/composite/Main.java b/src/main/java/com/shenyy/dp/composite/example01/Main.java
similarity index 97%
rename from src/main/java/com/mashibing/dp/composite/Main.java
rename to src/main/java/com/shenyy/dp/composite/example01/Main.java
index a25b3ed..ddcf9ca 100644
--- a/src/main/java/com/mashibing/dp/composite/Main.java
+++ b/src/main/java/com/shenyy/dp/composite/example01/Main.java
@@ -1,4 +1,4 @@
-package com.mashibing.dp.composite;
+package com.shenyy.dp.composite.example01;
import java.util.ArrayList;
import java.util.List;
diff --git a/src/main/java/com/shenyy/dp/cor/Description.md b/src/main/java/com/shenyy/dp/cor/Description.md
new file mode 100644
index 0000000..9d8b30f
--- /dev/null
+++ b/src/main/java/com/shenyy/dp/cor/Description.md
@@ -0,0 +1,33 @@
+##Description
+Chain of responsibility pattern is used to achieve loose coupling in software design where a request from the client is passed to a chain of objects to process them. Later, the object in the chain will decide themselves who will be processing the request and whether the request is required to be sent to the next object in the chain or not.
+
+
+###Where and When Chain of Responsibility pattern is applicable :
+* When you want to decouple a request’s sender and receiver
+* Multiple objects, determined at runtime, are candidates to handle a request
+* When you don’t want to specify handlers explicitly in your code
+* When you want to issue a request to one of several objects without specifying the receiver explicitly.
+
+This pattern is recommended when multiple objects can handle a request and the handler doesn’t have to be a specific object. Also, the handler is determined at runtime. Please note that a request not handled at all by any handler is a valid use case.
+
+
+
+* **Handler**: This can be an interface which will primarily receive the request and dispatches the request to a chain of handlers. It has reference to the only first handler in the chain and does not know anything about the rest of the handlers.
+* **Concrete handlers**: These are actual handlers of the request chained in some sequential order.
+* **Client**: Originator of request and this will access the handler to handle it.
+
+###How to send a request in the application using the Chain of Responsibility
+The Client in need of a request to be handled sends it to the chain of handlers which are classes that extend the Handler class.
+Each of the handlers in the chain takes its turn trying to handle the request it receives from the client.
+If ConcreteHandler1 can handle it, then the request is handled, if not it is sent to the handler ConcreteHandler2, the next one in the chain.
+
+###Advantages of Chain of Responsibility Design Pattern
+* To reduce the coupling degree. Decoupling it will request the sender and receiver.
+* Simplified object. The object does not need to know the chain structure.
+* Enhance flexibility of object assigned duties. By changing the members within the chain or change their order, allow dynamic adding or deleting responsibility.
+* Increase the request processing new class of very convenient.
+
+###DisAdvantages of Chain of Responsibility Design Pattern
+* The request must be received not guarantee.
+* The performance of the system will be affected, but also in the code debugging is not easy may cause cycle call.
+* It may not be easy to observe the characteristics of operation, due to debug.
\ No newline at end of file
diff --git a/src/main/java/com/shenyy/dp/cor/assets/desigmpatternuml1.png b/src/main/java/com/shenyy/dp/cor/assets/desigmpatternuml1.png
new file mode 100644
index 0000000..888130d
Binary files /dev/null and b/src/main/java/com/shenyy/dp/cor/assets/desigmpatternuml1.png differ
diff --git a/src/main/java/com/shenyy/dp/cor/chatgpt/EmailLogger.java b/src/main/java/com/shenyy/dp/cor/chatgpt/EmailLogger.java
new file mode 100644
index 0000000..d57c936
--- /dev/null
+++ b/src/main/java/com/shenyy/dp/cor/chatgpt/EmailLogger.java
@@ -0,0 +1,12 @@
+package com.shenyy.dp.cor.chatgpt;
+
+public class EmailLogger extends Logger {
+ public EmailLogger(int mask) {
+ this.mask = mask;
+ }
+
+ @Override
+ protected void writeMessage(String msg) {
+ System.out.println("Sending via email: " + msg);
+ }
+}
diff --git a/src/main/java/com/shenyy/dp/cor/chatgpt/Logger.java b/src/main/java/com/shenyy/dp/cor/chatgpt/Logger.java
new file mode 100644
index 0000000..fa1c10b
--- /dev/null
+++ b/src/main/java/com/shenyy/dp/cor/chatgpt/Logger.java
@@ -0,0 +1,29 @@
+package com.shenyy.dp.cor.chatgpt;
+
+abstract class Logger {
+ //set the priority
+ public static int ERR = 3;
+ public static int NOTICE = 5;
+ public static int DEBUG = 7;
+ protected int mask;
+
+ // The next element in the chain of responsibility
+ protected Logger next;
+
+ public Logger setNext(Logger next) {
+ this.next = next;
+ return next;
+ }
+
+ public void message(String msg, int priority) {
+ if (priority <= mask) {
+ writeMessage(msg);
+ }
+
+ if (next != null) {
+ next.message(msg, priority);
+ }
+ }
+
+ protected abstract void writeMessage(String msg);
+}
diff --git a/src/main/java/com/shenyy/dp/cor/chatgpt/StderrLogger.java b/src/main/java/com/shenyy/dp/cor/chatgpt/StderrLogger.java
new file mode 100644
index 0000000..9d8f97a
--- /dev/null
+++ b/src/main/java/com/shenyy/dp/cor/chatgpt/StderrLogger.java
@@ -0,0 +1,11 @@
+package com.shenyy.dp.cor.chatgpt;
+
+public class StderrLogger extends Logger {
+ public StderrLogger(int mask) {
+ this.mask = mask;
+ }
+
+ protected void writeMessage(String msg) {
+ System.out.println("Sending to stderr: " + msg);
+ }
+}
\ No newline at end of file
diff --git a/src/main/java/com/shenyy/dp/cor/chatgpt/StdoutLogger.java b/src/main/java/com/shenyy/dp/cor/chatgpt/StdoutLogger.java
new file mode 100644
index 0000000..45e6212
--- /dev/null
+++ b/src/main/java/com/shenyy/dp/cor/chatgpt/StdoutLogger.java
@@ -0,0 +1,12 @@
+package com.shenyy.dp.cor.chatgpt;
+
+public class StdoutLogger extends Logger {
+ public StdoutLogger(int mask) {
+ this.mask = mask;
+ }
+
+ @Override
+ protected void writeMessage(String msg) {
+ System.out.println("Writing to stdout: " + msg);
+ }
+}
diff --git a/src/main/java/com/shenyy/dp/cor/chatgpt/corExample.java b/src/main/java/com/shenyy/dp/cor/chatgpt/corExample.java
new file mode 100644
index 0000000..a1325fe
--- /dev/null
+++ b/src/main/java/com/shenyy/dp/cor/chatgpt/corExample.java
@@ -0,0 +1,20 @@
+package com.shenyy.dp.cor.chatgpt;
+
+public class corExample {
+ public static void main(String[] args) {
+ // Build the chain of responsibility
+ Logger logger, logger1, logger2;
+ logger = new StdoutLogger(Logger.DEBUG);
+ logger1 = logger.setNext(new EmailLogger(Logger.NOTICE));
+ logger2 = logger1.setNext(new StderrLogger(Logger.ERR));
+
+ // Handled by StdoutLogger
+ logger.message("Entering function y.", Logger.DEBUG);
+
+ // Handled by StdoutLogger and EmailLogger
+ logger.message("Step1 completed.", Logger.NOTICE);
+
+ // Handled by all three loggers
+ logger.message("An error has occurred.", Logger.ERR);
+ }
+}
diff --git a/src/main/java/com/mashibing/dp/cor/Main.java b/src/main/java/com/shenyy/dp/cor/example01/main/Main.java
similarity index 98%
rename from src/main/java/com/mashibing/dp/cor/Main.java
rename to src/main/java/com/shenyy/dp/cor/example01/main/Main.java
index 8c6b66b..db78a8d 100644
--- a/src/main/java/com/mashibing/dp/cor/Main.java
+++ b/src/main/java/com/shenyy/dp/cor/example01/main/Main.java
@@ -1,4 +1,4 @@
-package com.mashibing.dp.cor;
+package com.shenyy.dp.cor.example01.main;
import java.util.ArrayList;
import java.util.List;
diff --git a/src/main/java/com/mashibing/dp/cor/Main.java.bak b/src/main/java/com/shenyy/dp/cor/example01/main/Main.java.bak
similarity index 98%
rename from src/main/java/com/mashibing/dp/cor/Main.java.bak
rename to src/main/java/com/shenyy/dp/cor/example01/main/Main.java.bak
index aa2ca30..ad00cf5 100644
--- a/src/main/java/com/mashibing/dp/cor/Main.java.bak
+++ b/src/main/java/com/shenyy/dp/cor/example01/main/Main.java.bak
@@ -1,4 +1,4 @@
-package com.mashibing.dp.cor;
+package com.shenyy.dp.cor;
import java.util.ArrayList;
import java.util.List;
diff --git a/src/main/java/com/mashibing/dp/cor/servlet/v1/Servlet_Main.java b/src/main/java/com/shenyy/dp/cor/example01/servlet/v1/Servlet_Main.java
similarity index 96%
rename from src/main/java/com/mashibing/dp/cor/servlet/v1/Servlet_Main.java
rename to src/main/java/com/shenyy/dp/cor/example01/servlet/v1/Servlet_Main.java
index df5b129..0d62f2d 100644
--- a/src/main/java/com/mashibing/dp/cor/servlet/v1/Servlet_Main.java
+++ b/src/main/java/com/shenyy/dp/cor/example01/servlet/v1/Servlet_Main.java
@@ -1,4 +1,4 @@
-package com.mashibing.dp.cor.servlet.v1;
+package com.shenyy.dp.cor.example01.servlet.v1;
import java.util.ArrayList;
import java.util.List;
diff --git a/src/main/java/com/mashibing/dp/cor/servlet/v2/Servlet_Main.java b/src/main/java/com/shenyy/dp/cor/example01/servlet/v2/Servlet_Main.java
similarity index 97%
rename from src/main/java/com/mashibing/dp/cor/servlet/v2/Servlet_Main.java
rename to src/main/java/com/shenyy/dp/cor/example01/servlet/v2/Servlet_Main.java
index 3eafa38..9531039 100644
--- a/src/main/java/com/mashibing/dp/cor/servlet/v2/Servlet_Main.java
+++ b/src/main/java/com/shenyy/dp/cor/example01/servlet/v2/Servlet_Main.java
@@ -1,4 +1,4 @@
-package com.mashibing.dp.cor.servlet.v2;
+package com.shenyy.dp.cor.example01.servlet.v2;
import java.util.ArrayList;
import java.util.List;
diff --git a/src/main/java/com/mashibing/dp/cor/servlet/v2/readme b/src/main/java/com/shenyy/dp/cor/example01/servlet/v2/readme
similarity index 100%
rename from src/main/java/com/mashibing/dp/cor/servlet/v2/readme
rename to src/main/java/com/shenyy/dp/cor/example01/servlet/v2/readme
diff --git a/src/main/java/com/mashibing/dp/cor/servlet/v3/Servlet_Main.java b/src/main/java/com/shenyy/dp/cor/example01/servlet/v3/Servlet_Main.java
similarity index 97%
rename from src/main/java/com/mashibing/dp/cor/servlet/v3/Servlet_Main.java
rename to src/main/java/com/shenyy/dp/cor/example01/servlet/v3/Servlet_Main.java
index 376011d..66c90b5 100644
--- a/src/main/java/com/mashibing/dp/cor/servlet/v3/Servlet_Main.java
+++ b/src/main/java/com/shenyy/dp/cor/example01/servlet/v3/Servlet_Main.java
@@ -1,4 +1,4 @@
-package com.mashibing.dp.cor.servlet.v3;
+package com.shenyy.dp.cor.example01.servlet.v3;
import java.util.ArrayList;
import java.util.List;
diff --git a/src/main/java/com/mashibing/dp/cor/servlet/v3/readme b/src/main/java/com/shenyy/dp/cor/example01/servlet/v3/readme
similarity index 100%
rename from src/main/java/com/mashibing/dp/cor/servlet/v3/readme
rename to src/main/java/com/shenyy/dp/cor/example01/servlet/v3/readme
diff --git a/src/main/java/com/mashibing/dp/cor/servlet/v4/Servlet_Main.java b/src/main/java/com/shenyy/dp/cor/example01/servlet/v4/Servlet_Main.java
similarity index 97%
rename from src/main/java/com/mashibing/dp/cor/servlet/v4/Servlet_Main.java
rename to src/main/java/com/shenyy/dp/cor/example01/servlet/v4/Servlet_Main.java
index a401ee5..2c9aa9e 100644
--- a/src/main/java/com/mashibing/dp/cor/servlet/v4/Servlet_Main.java
+++ b/src/main/java/com/shenyy/dp/cor/example01/servlet/v4/Servlet_Main.java
@@ -1,4 +1,4 @@
-package com.mashibing.dp.cor.servlet.v4;
+package com.shenyy.dp.cor.example01.servlet.v4;
import java.util.ArrayList;
import java.util.List;
diff --git a/src/main/java/com/mashibing/dp/cor/servlet/v4/readme b/src/main/java/com/shenyy/dp/cor/example01/servlet/v4/readme
similarity index 100%
rename from src/main/java/com/mashibing/dp/cor/servlet/v4/readme
rename to src/main/java/com/shenyy/dp/cor/example01/servlet/v4/readme
diff --git a/src/main/java/com/mashibing/dp/decorator/Main.java b/src/main/java/com/shenyy/dp/decorator/example01/Main.java
similarity index 90%
rename from src/main/java/com/mashibing/dp/decorator/Main.java
rename to src/main/java/com/shenyy/dp/decorator/example01/Main.java
index eb9a12b..c781fb4 100644
--- a/src/main/java/com/mashibing/dp/decorator/Main.java
+++ b/src/main/java/com/shenyy/dp/decorator/example01/Main.java
@@ -1,4 +1,4 @@
-package com.mashibing.dp.decorator;
+package com.shenyy.dp.decorator.example01;
import java.io.*;
diff --git a/src/main/java/com/mashibing/dp/decorator/readme b/src/main/java/com/shenyy/dp/decorator/example01/readme
similarity index 100%
rename from src/main/java/com/mashibing/dp/decorator/readme
rename to src/main/java/com/shenyy/dp/decorator/example01/readme
diff --git a/src/main/java/com/shenyy/dp/decorator/exercise/Bottom.java b/src/main/java/com/shenyy/dp/decorator/exercise/Bottom.java
new file mode 100644
index 0000000..f426993
--- /dev/null
+++ b/src/main/java/com/shenyy/dp/decorator/exercise/Bottom.java
@@ -0,0 +1,15 @@
+package com.shenyy.dp.decorator.exercise;
+
+public abstract class Bottom {
+ private String description = "Unknown bottom";
+
+ public String getDescription() {
+ return description;
+ }
+
+ public void setDescription(String description) {
+ this.description = description;
+ }
+
+ public abstract int getCost();
+}
diff --git a/src/main/java/com/shenyy/dp/decorator/exercise/DecoratorExample.java b/src/main/java/com/shenyy/dp/decorator/exercise/DecoratorExample.java
new file mode 100644
index 0000000..fb30617
--- /dev/null
+++ b/src/main/java/com/shenyy/dp/decorator/exercise/DecoratorExample.java
@@ -0,0 +1,17 @@
+package com.shenyy.dp.decorator.exercise;
+
+public class DecoratorExample {
+ public static void main(String[] args) {
+ Bottom bottom = new SteelBottom();
+ bottom = new ToppingA(bottom);
+ bottom = new ToppingB(bottom);
+ System.out.println(bottom.getDescription() + " Cost: " + bottom.getCost());
+
+ Bottom bottom1 = new GlassBottom();
+ bottom1 = new ToppingB(bottom1);
+ bottom1 = new ToppingB(bottom1);
+ bottom1 = new ToppingB(bottom1);
+ bottom1 = new ToppingB(bottom1);
+ System.out.println(bottom1.getDescription() + " Cost: " + bottom1.getCost());
+ }
+}
diff --git a/src/main/java/com/shenyy/dp/decorator/exercise/GlassBottom.java b/src/main/java/com/shenyy/dp/decorator/exercise/GlassBottom.java
new file mode 100644
index 0000000..d4200b4
--- /dev/null
+++ b/src/main/java/com/shenyy/dp/decorator/exercise/GlassBottom.java
@@ -0,0 +1,12 @@
+package com.shenyy.dp.decorator.exercise;
+
+public class GlassBottom extends Bottom{
+ @Override
+ public int getCost() {
+ return 200;
+ }
+
+ public GlassBottom() {
+ setDescription("GlassBottom");
+ }
+}
diff --git a/src/main/java/com/shenyy/dp/decorator/exercise/SteelBottom.java b/src/main/java/com/shenyy/dp/decorator/exercise/SteelBottom.java
new file mode 100644
index 0000000..becabbc
--- /dev/null
+++ b/src/main/java/com/shenyy/dp/decorator/exercise/SteelBottom.java
@@ -0,0 +1,12 @@
+package com.shenyy.dp.decorator.exercise;
+
+public class SteelBottom extends Bottom {
+ public SteelBottom() {
+ setDescription("SteelBottom");
+ }
+
+ @Override
+ public int getCost() {
+ return 100;
+ }
+}
diff --git a/src/main/java/com/shenyy/dp/decorator/exercise/ToppingA.java b/src/main/java/com/shenyy/dp/decorator/exercise/ToppingA.java
new file mode 100644
index 0000000..1f64399
--- /dev/null
+++ b/src/main/java/com/shenyy/dp/decorator/exercise/ToppingA.java
@@ -0,0 +1,19 @@
+package com.shenyy.dp.decorator.exercise;
+
+public class ToppingA extends ToppingsDecorator {
+ Bottom bottom;
+
+ public ToppingA(Bottom bottom) {
+ this.bottom = bottom;
+ }
+
+ @Override
+ public int getCost() {
+ return bottom.getCost() + 100;
+ }
+
+ @Override
+ public String getDescription() {
+ return bottom.getDescription() + ", ToppingA";
+ }
+}
diff --git a/src/main/java/com/shenyy/dp/decorator/exercise/ToppingB.java b/src/main/java/com/shenyy/dp/decorator/exercise/ToppingB.java
new file mode 100644
index 0000000..5f54f41
--- /dev/null
+++ b/src/main/java/com/shenyy/dp/decorator/exercise/ToppingB.java
@@ -0,0 +1,19 @@
+package com.shenyy.dp.decorator.exercise;
+
+public class ToppingB extends ToppingsDecorator{
+ Bottom bottom;
+
+ public ToppingB(Bottom bottom) {
+ this.bottom = bottom;
+ }
+
+ @Override
+ public int getCost() {
+ return bottom.getCost() + 50;
+ }
+
+ @Override
+ public String getDescription() {
+ return bottom.getDescription() + ", ToppingB";
+ }
+}
diff --git a/src/main/java/com/shenyy/dp/decorator/exercise/ToppingsDecorator.java b/src/main/java/com/shenyy/dp/decorator/exercise/ToppingsDecorator.java
new file mode 100644
index 0000000..f01fe4c
--- /dev/null
+++ b/src/main/java/com/shenyy/dp/decorator/exercise/ToppingsDecorator.java
@@ -0,0 +1,5 @@
+package com.shenyy.dp.decorator.exercise;
+
+public abstract class ToppingsDecorator extends Bottom {
+ public abstract String getDescription();
+}
diff --git a/src/main/java/com/shenyy/dp/facade/Description.md b/src/main/java/com/shenyy/dp/facade/Description.md
new file mode 100644
index 0000000..6486f08
--- /dev/null
+++ b/src/main/java/com/shenyy/dp/facade/Description.md
@@ -0,0 +1,9 @@
+##Description
+
+The facade pattern is appropriate when you have a complex system that you want to expose to clients in a simplified way, or you want to make an external communication layer over an existing system which is incompatible with the system. Facade deals with interfaces, not implementation. Its purpose is to hide internal complexity behind a single interface that appears simple on the outside.
+
+In Java, the interface JDBC can be called a facade because, we as users or clients create connection using the “java.sql.Connection” interface, the implementation of which we are not concerned about. The implementation is left to the vendor of driver. Another good example can be the startup of a computer. When a computer starts up, it involves the work of cpu, memory, hard drive, etc. To make it easy to use for users, we can add a facade which wrap the complexity of the task, and provide one simple interface instead. Same goes for the Facade Design Pattern. It hides the complexities of the system and provides an interface to the client from where the client can access
+
+
+
+This example shows a Facade class that provides a unified interface to a set of individual systems (SystemA, SystemB, and SystemC). The main method creates an instance of the Facade class and calls the methodA, methodB, and methodC methods, which in turn call the corresponding methods in the individual systems.
\ No newline at end of file
diff --git a/src/main/java/com/shenyy/dp/facade/assets/facadeA.png b/src/main/java/com/shenyy/dp/facade/assets/facadeA.png
new file mode 100644
index 0000000..e5914bf
Binary files /dev/null and b/src/main/java/com/shenyy/dp/facade/assets/facadeA.png differ
diff --git a/src/main/java/com/shenyy/dp/facade/chatgpt/Facade.java b/src/main/java/com/shenyy/dp/facade/chatgpt/Facade.java
new file mode 100644
index 0000000..76d8ad9
--- /dev/null
+++ b/src/main/java/com/shenyy/dp/facade/chatgpt/Facade.java
@@ -0,0 +1,33 @@
+package com.shenyy.dp.facade.chatgpt;
+
+public class Facade {
+ public static void main(String[] args) {
+ Facade facade = new Facade();
+ facade.methodA();
+ facade.methodB();
+ facade.methodC();
+ }
+
+ private SystemA systemA;
+ private SystemB systemB;
+ private SystemC systemC;
+
+ public Facade() {
+ this.systemA = new SystemA();
+ this.systemB = new SystemB();
+ this.systemC = new SystemC();
+ }
+
+ public void methodA() {
+ systemA.methodA();
+ }
+
+ public void methodB() {
+ systemB.methodB();
+ }
+
+ public void methodC() {
+ systemC.methodC();
+ }
+
+}
diff --git a/src/main/java/com/shenyy/dp/facade/chatgpt/SystemA.java b/src/main/java/com/shenyy/dp/facade/chatgpt/SystemA.java
new file mode 100644
index 0000000..a38798c
--- /dev/null
+++ b/src/main/java/com/shenyy/dp/facade/chatgpt/SystemA.java
@@ -0,0 +1,7 @@
+package com.shenyy.dp.facade.chatgpt;
+
+public class SystemA {
+ public void methodA() {
+ System.out.println("Method A of System A is called");
+ }
+}
diff --git a/src/main/java/com/shenyy/dp/facade/chatgpt/SystemB.java b/src/main/java/com/shenyy/dp/facade/chatgpt/SystemB.java
new file mode 100644
index 0000000..8818bf4
--- /dev/null
+++ b/src/main/java/com/shenyy/dp/facade/chatgpt/SystemB.java
@@ -0,0 +1,7 @@
+package com.shenyy.dp.facade.chatgpt;
+
+public class SystemB {
+ public void methodB() {
+ System.out.println("Method B of System B is called");
+ }
+}
diff --git a/src/main/java/com/shenyy/dp/facade/chatgpt/SystemC.java b/src/main/java/com/shenyy/dp/facade/chatgpt/SystemC.java
new file mode 100644
index 0000000..942f78b
--- /dev/null
+++ b/src/main/java/com/shenyy/dp/facade/chatgpt/SystemC.java
@@ -0,0 +1,7 @@
+package com.shenyy.dp.facade.chatgpt;
+
+public class SystemC {
+ public void methodC() {
+ System.out.println("Method C of System C is called");
+ }
+}
diff --git a/src/main/java/com/shenyy/dp/facade/exercise/Client.java b/src/main/java/com/shenyy/dp/facade/exercise/Client.java
new file mode 100644
index 0000000..697dcd6
--- /dev/null
+++ b/src/main/java/com/shenyy/dp/facade/exercise/Client.java
@@ -0,0 +1,10 @@
+package com.shenyy.dp.facade.exercise;
+
+public class Client {
+ public static void main(String[] args) {
+ Keeper restaurantKeeper = new RestaurantKeeper();
+ restaurantKeeper.getVegMenu();
+ restaurantKeeper.getNonVegMenu();
+ restaurantKeeper.getVegNonMenu();
+ }
+}
diff --git a/src/main/java/com/shenyy/dp/facade/exercise/Keeper.java b/src/main/java/com/shenyy/dp/facade/exercise/Keeper.java
new file mode 100644
index 0000000..5bf6d04
--- /dev/null
+++ b/src/main/java/com/shenyy/dp/facade/exercise/Keeper.java
@@ -0,0 +1,9 @@
+package com.shenyy.dp.facade.exercise;
+
+public interface Keeper {
+ public Menu getVegMenu();
+
+ public Menu getNonVegMenu();
+
+ public Menu getVegNonMenu();
+}
diff --git a/src/main/java/com/shenyy/dp/facade/exercise/Menu.java b/src/main/java/com/shenyy/dp/facade/exercise/Menu.java
new file mode 100644
index 0000000..e85f096
--- /dev/null
+++ b/src/main/java/com/shenyy/dp/facade/exercise/Menu.java
@@ -0,0 +1,9 @@
+package com.shenyy.dp.facade.exercise;
+
+public class Menu {
+ private String content;
+
+ public Menu(String content) {
+ this.content = content;
+ }
+}
diff --git a/src/main/java/com/shenyy/dp/facade/exercise/NonVegRestaurant.java b/src/main/java/com/shenyy/dp/facade/exercise/NonVegRestaurant.java
new file mode 100644
index 0000000..cbebbb4
--- /dev/null
+++ b/src/main/java/com/shenyy/dp/facade/exercise/NonVegRestaurant.java
@@ -0,0 +1,9 @@
+package com.shenyy.dp.facade.exercise;
+
+public class NonVegRestaurant implements Restaurant{
+ @Override
+ public Menu getMenu() {
+ System.out.println("NonVeg");
+ return new Menu("NonVeg");
+ }
+}
diff --git a/src/main/java/com/shenyy/dp/facade/exercise/Restaurant.java b/src/main/java/com/shenyy/dp/facade/exercise/Restaurant.java
new file mode 100644
index 0000000..e53a4e0
--- /dev/null
+++ b/src/main/java/com/shenyy/dp/facade/exercise/Restaurant.java
@@ -0,0 +1,5 @@
+package com.shenyy.dp.facade.exercise;
+
+public interface Restaurant {
+ public Menu getMenu();
+}
diff --git a/src/main/java/com/shenyy/dp/facade/exercise/RestaurantKeeper.java b/src/main/java/com/shenyy/dp/facade/exercise/RestaurantKeeper.java
new file mode 100644
index 0000000..dcd2102
--- /dev/null
+++ b/src/main/java/com/shenyy/dp/facade/exercise/RestaurantKeeper.java
@@ -0,0 +1,22 @@
+package com.shenyy.dp.facade.exercise;
+
+public class RestaurantKeeper implements Keeper {
+
+ @Override
+ public Menu getVegMenu() {
+ VegRestaurant vegRestaurant = new VegRestaurant();
+ return vegRestaurant.getMenu();
+ }
+
+ @Override
+ public Menu getNonVegMenu() {
+ NonVegRestaurant nonVegRestaurant = new NonVegRestaurant();
+ return nonVegRestaurant.getMenu();
+ }
+
+ @Override
+ public Menu getVegNonMenu() {
+ VegNonRestaurant vegNonRestaurant = new VegNonRestaurant();
+ return vegNonRestaurant.getMenu();
+ }
+}
diff --git a/src/main/java/com/shenyy/dp/facade/exercise/VegNonRestaurant.java b/src/main/java/com/shenyy/dp/facade/exercise/VegNonRestaurant.java
new file mode 100644
index 0000000..8b253d3
--- /dev/null
+++ b/src/main/java/com/shenyy/dp/facade/exercise/VegNonRestaurant.java
@@ -0,0 +1,9 @@
+package com.shenyy.dp.facade.exercise;
+
+public class VegNonRestaurant implements Restaurant {
+ @Override
+ public Menu getMenu() {
+ System.out.println("VegNon");
+ return new Menu("VegNon");
+ }
+}
diff --git a/src/main/java/com/shenyy/dp/facade/exercise/VegRestaurant.java b/src/main/java/com/shenyy/dp/facade/exercise/VegRestaurant.java
new file mode 100644
index 0000000..c1841b5
--- /dev/null
+++ b/src/main/java/com/shenyy/dp/facade/exercise/VegRestaurant.java
@@ -0,0 +1,9 @@
+package com.shenyy.dp.facade.exercise;
+
+public class VegRestaurant implements Restaurant{
+ @Override
+ public Menu getMenu() {
+ System.out.println("Veg");
+ return new Menu("Veg");
+ }
+}
diff --git a/src/main/java/com/shenyy/dp/factorymethod/chatgpt/Cake.java b/src/main/java/com/shenyy/dp/factorymethod/chatgpt/Cake.java
new file mode 100644
index 0000000..7851c60
--- /dev/null
+++ b/src/main/java/com/shenyy/dp/factorymethod/chatgpt/Cake.java
@@ -0,0 +1,8 @@
+package com.shenyy.dp.factorymethod.chatgpt;
+
+public class Cake extends Dessert {
+ @Override
+ void make() {
+ System.out.println("Making a cake");
+ }
+}
diff --git a/src/main/java/com/shenyy/dp/factorymethod/chatgpt/Dessert.java b/src/main/java/com/shenyy/dp/factorymethod/chatgpt/Dessert.java
new file mode 100644
index 0000000..fafabd0
--- /dev/null
+++ b/src/main/java/com/shenyy/dp/factorymethod/chatgpt/Dessert.java
@@ -0,0 +1,5 @@
+package com.shenyy.dp.factorymethod.chatgpt;
+
+public abstract class Dessert {
+ abstract void make();
+}
diff --git a/src/main/java/com/shenyy/dp/factorymethod/chatgpt/DessertFactory.java b/src/main/java/com/shenyy/dp/factorymethod/chatgpt/DessertFactory.java
new file mode 100644
index 0000000..0eff9c3
--- /dev/null
+++ b/src/main/java/com/shenyy/dp/factorymethod/chatgpt/DessertFactory.java
@@ -0,0 +1,17 @@
+package com.shenyy.dp.factorymethod.chatgpt;
+
+public class DessertFactory {
+ Dessert getDessert(String dessertType) {
+ if (dessertType == null) {
+ return null;
+ }
+ if (dessertType.equalsIgnoreCase("CAKE")) {
+ return new Cake();
+ } else if (dessertType.equalsIgnoreCase("PIE")) {
+ return new Pie();
+ } else if (dessertType.equalsIgnoreCase("ICECREAM")) {
+ return new IceCream();
+ }
+ return null;
+ }
+}
diff --git a/src/main/java/com/shenyy/dp/factorymethod/chatgpt/FactoryMethodExample.java b/src/main/java/com/shenyy/dp/factorymethod/chatgpt/FactoryMethodExample.java
new file mode 100644
index 0000000..ac9265e
--- /dev/null
+++ b/src/main/java/com/shenyy/dp/factorymethod/chatgpt/FactoryMethodExample.java
@@ -0,0 +1,10 @@
+package com.shenyy.dp.factorymethod.chatgpt;
+
+public class FactoryMethodExample {
+ public static void main(String[] args) {
+ Dessert dessert = new DessertFactory().getDessert("Cake");
+ dessert.make();
+ Dessert dessert1 = new DessertFactory().getDessert("Pie");
+ dessert1.make();
+ }
+}
diff --git a/src/main/java/com/shenyy/dp/factorymethod/chatgpt/IceCream.java b/src/main/java/com/shenyy/dp/factorymethod/chatgpt/IceCream.java
new file mode 100644
index 0000000..0025e60
--- /dev/null
+++ b/src/main/java/com/shenyy/dp/factorymethod/chatgpt/IceCream.java
@@ -0,0 +1,8 @@
+package com.shenyy.dp.factorymethod.chatgpt;
+
+public class IceCream extends Dessert {
+ @Override
+ void make() {
+ System.out.println("Making an ice cream");
+ }
+}
diff --git a/src/main/java/com/shenyy/dp/factorymethod/chatgpt/Pie.java b/src/main/java/com/shenyy/dp/factorymethod/chatgpt/Pie.java
new file mode 100644
index 0000000..8f78f01
--- /dev/null
+++ b/src/main/java/com/shenyy/dp/factorymethod/chatgpt/Pie.java
@@ -0,0 +1,8 @@
+package com.shenyy.dp.factorymethod.chatgpt;
+
+public class Pie extends Dessert {
+ @Override
+ void make() {
+ System.out.println("Making a pie");
+ }
+}
diff --git "a/src/main/java/com/shenyy/dp/factorymethod/chatgpt/\345\267\245\345\216\202\346\226\271\346\263\225\346\250\241\345\274\217\347\244\272\344\276\213.md" "b/src/main/java/com/shenyy/dp/factorymethod/chatgpt/\345\267\245\345\216\202\346\226\271\346\263\225\346\250\241\345\274\217\347\244\272\344\276\213.md"
new file mode 100644
index 0000000..0121314
--- /dev/null
+++ "b/src/main/java/com/shenyy/dp/factorymethod/chatgpt/\345\267\245\345\216\202\346\226\271\346\263\225\346\250\241\345\274\217\347\244\272\344\276\213.md"
@@ -0,0 +1,8 @@
+##工厂方法模式示例
+假设您有一家甜点店,您可以使用工厂方法模式来处理制作不同类型的甜点。
+
+首先,创建一个抽象甜点类,名为Dessert,它包含了制作甜点的抽象方法。
+
+然后,创建多个具体的甜点类,如Cake,Pie和IceCream,它们继承了Dessert类并实现了制作甜点的方法。
+
+最后,创建一个工厂类,名为DessertFactory,它包含了制作甜点的工厂方法。该方法将返回抽象甜点类的具体实现。
\ No newline at end of file
diff --git a/src/main/java/com/mashibing/dp/factorymethod/Broom.java b/src/main/java/com/shenyy/dp/factorymethod/example01/Broom.java
similarity index 76%
rename from src/main/java/com/mashibing/dp/factorymethod/Broom.java
rename to src/main/java/com/shenyy/dp/factorymethod/example01/Broom.java
index ddcc76e..b9a1e72 100644
--- a/src/main/java/com/mashibing/dp/factorymethod/Broom.java
+++ b/src/main/java/com/shenyy/dp/factorymethod/example01/Broom.java
@@ -1,4 +1,4 @@
-package com.mashibing.dp.factorymethod;
+package com.shenyy.dp.factorymethod.example01;
public class Broom implements Moveable{
diff --git a/src/main/java/com/mashibing/dp/factorymethod/Car.java b/src/main/java/com/shenyy/dp/factorymethod/example01/Car.java
similarity index 72%
rename from src/main/java/com/mashibing/dp/factorymethod/Car.java
rename to src/main/java/com/shenyy/dp/factorymethod/example01/Car.java
index 03ea460..999b5b7 100644
--- a/src/main/java/com/mashibing/dp/factorymethod/Car.java
+++ b/src/main/java/com/shenyy/dp/factorymethod/example01/Car.java
@@ -1,4 +1,4 @@
-package com.mashibing.dp.factorymethod;
+package com.shenyy.dp.factorymethod.example01;
public class Car implements Moveable {
diff --git a/src/main/java/com/mashibing/dp/factorymethod/CarFactory.java b/src/main/java/com/shenyy/dp/factorymethod/example01/CarFactory.java
similarity index 74%
rename from src/main/java/com/mashibing/dp/factorymethod/CarFactory.java
rename to src/main/java/com/shenyy/dp/factorymethod/example01/CarFactory.java
index c698c8f..2c19d26 100644
--- a/src/main/java/com/mashibing/dp/factorymethod/CarFactory.java
+++ b/src/main/java/com/shenyy/dp/factorymethod/example01/CarFactory.java
@@ -1,4 +1,4 @@
-package com.mashibing.dp.factorymethod;
+package com.shenyy.dp.factorymethod.example01;
public class CarFactory {
public Moveable create() {
diff --git a/src/main/java/com/mashibing/dp/factorymethod/Main.java b/src/main/java/com/shenyy/dp/factorymethod/example01/Main.java
similarity index 74%
rename from src/main/java/com/mashibing/dp/factorymethod/Main.java
rename to src/main/java/com/shenyy/dp/factorymethod/example01/Main.java
index b87800a..0dcd677 100644
--- a/src/main/java/com/mashibing/dp/factorymethod/Main.java
+++ b/src/main/java/com/shenyy/dp/factorymethod/example01/Main.java
@@ -1,4 +1,4 @@
-package com.mashibing.dp.factorymethod;
+package com.shenyy.dp.factorymethod.example01;
public class Main {
public static void main(String[] args) {
diff --git a/src/main/java/com/shenyy/dp/factorymethod/example01/Moveable.java b/src/main/java/com/shenyy/dp/factorymethod/example01/Moveable.java
new file mode 100644
index 0000000..9b1340f
--- /dev/null
+++ b/src/main/java/com/shenyy/dp/factorymethod/example01/Moveable.java
@@ -0,0 +1,5 @@
+package com.shenyy.dp.factorymethod.example01;
+
+public interface Moveable {
+ void go();
+}
diff --git a/src/main/java/com/mashibing/dp/factorymethod/Plane.java b/src/main/java/com/shenyy/dp/factorymethod/example01/Plane.java
similarity index 73%
rename from src/main/java/com/mashibing/dp/factorymethod/Plane.java
rename to src/main/java/com/shenyy/dp/factorymethod/example01/Plane.java
index e60045f..29d9000 100644
--- a/src/main/java/com/mashibing/dp/factorymethod/Plane.java
+++ b/src/main/java/com/shenyy/dp/factorymethod/example01/Plane.java
@@ -1,4 +1,4 @@
-package com.mashibing.dp.factorymethod;
+package com.shenyy.dp.factorymethod.example01;
public class Plane implements Moveable {
public void go() {
diff --git a/src/main/java/com/mashibing/dp/factorymethod/SimpleVehicleFactory.java b/src/main/java/com/shenyy/dp/factorymethod/example01/SimpleVehicleFactory.java
similarity index 70%
rename from src/main/java/com/mashibing/dp/factorymethod/SimpleVehicleFactory.java
rename to src/main/java/com/shenyy/dp/factorymethod/example01/SimpleVehicleFactory.java
index ba9b902..012d5ca 100644
--- a/src/main/java/com/mashibing/dp/factorymethod/SimpleVehicleFactory.java
+++ b/src/main/java/com/shenyy/dp/factorymethod/example01/SimpleVehicleFactory.java
@@ -1,4 +1,4 @@
-package com.mashibing.dp.factorymethod;
+package com.shenyy.dp.factorymethod.example01;
/**
* 简单工厂的可扩展性不好
@@ -12,4 +12,6 @@ public Car createCar() {
public Broom createBroom() {
return new Broom();
}
+
+ public Plane createPlane() {return new Plane();}
}
diff --git a/src/main/java/com/shenyy/dp/flyweight/Description.md b/src/main/java/com/shenyy/dp/flyweight/Description.md
new file mode 100644
index 0000000..c878e48
--- /dev/null
+++ b/src/main/java/com/shenyy/dp/flyweight/Description.md
@@ -0,0 +1,16 @@
+##Description
+
+Flyweight pattern is one of the structural design patterns as this pattern provides ways to decrease object count thus improving application required objects structure. Flyweight pattern is used when we need to create a large number of similar objects (say 10^5). One important feature of flyweight objects is that they are immutable. This means that they cannot be modified once they have been constructed.
+
+###Why do we care for number of objects in our program?
+* Less number of objects reduces the memory usage, and it manages to keep us away from errors related to memory like java.lang.OutOfMemoryError.
+* Although creating an object in Java is really fast, we can still reduce the execution time of our program by sharing objects.
+
+In Flyweight pattern we use a HashMap that stores reference to the object which have already been created, every object is associated with a key. Now when a client wants to create an object, he simply has to pass a key associated with it and if the object has already been created we simply get the reference to that object else it creates a new object and then returns it reference to the client.
+
+###Intrinsic and Extrinsic States
+To understand Intrinsic and Extrinsic state, let us consider an example.
+
+Suppose in a text editor when we enter a character, an object of Character class is created, the attributes of the Character class are {name, font, size}. We do not need to create an object every time client enters a character since letter ‘B’ is no different from another ‘B’ . If client again types a ‘B’ we simply return the object which we have already created before. Now all these are intrinsic states (name, font, size), since they can be shared among the different objects as they are similar to each other.
+
+Now we add to more attributes to the Character class, they are row and column. They specify the position of a character in the document. Now these attributes will not be similar even for same characters, since no two characters will have the same position in a document, these states are termed as extrinsic states, and they can’t be shared among objects.
diff --git a/src/main/java/com/shenyy/dp/flyweight/chatgpt/ConcreteFlyweight.java b/src/main/java/com/shenyy/dp/flyweight/chatgpt/ConcreteFlyweight.java
new file mode 100644
index 0000000..c325fc3
--- /dev/null
+++ b/src/main/java/com/shenyy/dp/flyweight/chatgpt/ConcreteFlyweight.java
@@ -0,0 +1,14 @@
+package com.shenyy.dp.flyweight.chatgpt;
+
+public class ConcreteFlyweight implements Flyweight {
+ private int intrinsicState;
+
+ public ConcreteFlyweight(int intrinsicState) {
+ this.intrinsicState = intrinsicState;
+ }
+
+ @Override
+ public void operation(int extrinsicState) {
+ System.out.println("Intrinsic State: " + intrinsicState + " Extrinsic State: " + extrinsicState);
+ }
+}
diff --git a/src/main/java/com/shenyy/dp/flyweight/chatgpt/Flyweight.java b/src/main/java/com/shenyy/dp/flyweight/chatgpt/Flyweight.java
new file mode 100644
index 0000000..d6fc298
--- /dev/null
+++ b/src/main/java/com/shenyy/dp/flyweight/chatgpt/Flyweight.java
@@ -0,0 +1,5 @@
+package com.shenyy.dp.flyweight.chatgpt;
+
+public interface Flyweight {
+ void operation(int extrinsicState);
+}
diff --git a/src/main/java/com/shenyy/dp/flyweight/chatgpt/FlyweightExample.java b/src/main/java/com/shenyy/dp/flyweight/chatgpt/FlyweightExample.java
new file mode 100644
index 0000000..512a4a3
--- /dev/null
+++ b/src/main/java/com/shenyy/dp/flyweight/chatgpt/FlyweightExample.java
@@ -0,0 +1,15 @@
+package com.shenyy.dp.flyweight.chatgpt;
+
+public class FlyweightExample {
+ public static void main(String[] args) {
+ FlyweightFactory factory = new FlyweightFactory();
+ Flyweight flyweight1 = factory.getFlyweight(1);
+ Flyweight flyweight2 = factory.getFlyweight(2);
+ Flyweight flyweight3 = factory.getFlyweight(1);
+
+ flyweight1.operation(100);
+ flyweight2.operation(200);
+ flyweight3.operation(300);
+ System.out.println("");
+ }
+}
diff --git a/src/main/java/com/shenyy/dp/flyweight/chatgpt/FlyweightFactory.java b/src/main/java/com/shenyy/dp/flyweight/chatgpt/FlyweightFactory.java
new file mode 100644
index 0000000..879893f
--- /dev/null
+++ b/src/main/java/com/shenyy/dp/flyweight/chatgpt/FlyweightFactory.java
@@ -0,0 +1,15 @@
+package com.shenyy.dp.flyweight.chatgpt;
+
+import java.util.HashMap;
+import java.util.Map;
+
+public class FlyweightFactory {
+ private static Map flyweights = new HashMap<>();
+
+ Flyweight getFlyweight(int key) {
+ if (!flyweights.containsKey(key)) {
+ flyweights.put(key, new ConcreteFlyweight(key));
+ }
+ return flyweights.get(key);
+ }
+}
diff --git a/src/main/java/com/mashibing/dp/flyweight/BulletPool.java b/src/main/java/com/shenyy/dp/flyweight/example01/BulletPool.java
similarity index 72%
rename from src/main/java/com/mashibing/dp/flyweight/BulletPool.java
rename to src/main/java/com/shenyy/dp/flyweight/example01/BulletPool.java
index c4bd5a5..079eb07 100644
--- a/src/main/java/com/mashibing/dp/flyweight/BulletPool.java
+++ b/src/main/java/com/shenyy/dp/flyweight/example01/BulletPool.java
@@ -1,10 +1,10 @@
-package com.mashibing.dp.flyweight;
+package com.shenyy.dp.flyweight.example01;
import java.util.ArrayList;
import java.util.List;
import java.util.UUID;
-class Bullet{
+class Bullet {
public UUID id = UUID.randomUUID();
boolean living = true;
@@ -18,14 +18,15 @@ public String toString() {
public class BulletPool {
List bullets = new ArrayList<>();
+
{
- for(int i=0; i<5; i++) bullets.add(new Bullet());
+ for (int i = 0; i < 5; i++) bullets.add(new Bullet());
}
public Bullet getBullet() {
- for(int i=0; i mementos = new ArrayList<>();
+
+ public void add(Memento memento) {
+ mementos.add(memento);
+ }
+
+ public Memento get(int index) {
+ return mementos.get(index);
+ }
+}
diff --git a/src/main/java/com/shenyy/dp/memento/chatgpt/Memento.java b/src/main/java/com/shenyy/dp/memento/chatgpt/Memento.java
new file mode 100644
index 0000000..be6846f
--- /dev/null
+++ b/src/main/java/com/shenyy/dp/memento/chatgpt/Memento.java
@@ -0,0 +1,13 @@
+package com.shenyy.dp.memento.chatgpt;
+
+public class Memento {
+ private final String state;
+
+ public Memento(String state) {
+ this.state = state;
+ }
+
+ public String getState() {
+ return state;
+ }
+}
diff --git a/src/main/java/com/shenyy/dp/memento/chatgpt/MementoExample.java b/src/main/java/com/shenyy/dp/memento/chatgpt/MementoExample.java
new file mode 100644
index 0000000..2d20be8
--- /dev/null
+++ b/src/main/java/com/shenyy/dp/memento/chatgpt/MementoExample.java
@@ -0,0 +1,27 @@
+package com.shenyy.dp.memento.chatgpt;
+
+public class MementoExample {
+ public static void main(String[] args) {
+ Originator originator = new Originator();
+ CareTaker careTaker = new CareTaker();
+
+ originator.setState("State 1");
+ careTaker.add(originator.createMemento());
+
+ originator.setState("State 2");
+ careTaker.add(originator.createMemento());
+
+ originator.setState("State 3");
+ careTaker.add(originator.createMemento());
+
+ originator.setState("State 4");
+
+ System.out.println("Current State: " + originator.getState());
+
+ originator.restore(careTaker.get(0));
+ System.out.println("First saved State: " + originator.getState());
+
+ originator.restore(careTaker.get(1));
+ System.out.println("Second saved State: " + originator.getState());
+ }
+}
diff --git a/src/main/java/com/shenyy/dp/memento/chatgpt/Originator.java b/src/main/java/com/shenyy/dp/memento/chatgpt/Originator.java
new file mode 100644
index 0000000..7e3e605
--- /dev/null
+++ b/src/main/java/com/shenyy/dp/memento/chatgpt/Originator.java
@@ -0,0 +1,21 @@
+package com.shenyy.dp.memento.chatgpt;
+
+public class Originator {
+ private String state;
+
+ public String getState() {
+ return state;
+ }
+
+ public void setState(String state) {
+ this.state = state;
+ }
+
+ public Memento createMemento() {
+ return new Memento(state);
+ }
+
+ public void restore(Memento memento) {
+ this.state = memento.getState();
+ }
+}
diff --git a/src/main/java/com/mashibing/dp/memento/readme b/src/main/java/com/shenyy/dp/memento/readme
similarity index 100%
rename from src/main/java/com/mashibing/dp/memento/readme
rename to src/main/java/com/shenyy/dp/memento/readme
diff --git a/src/main/java/com/shenyy/dp/observer/Description.md b/src/main/java/com/shenyy/dp/observer/Description.md
new file mode 100644
index 0000000..bfbe57c
--- /dev/null
+++ b/src/main/java/com/shenyy/dp/observer/Description.md
@@ -0,0 +1,46 @@
+##Description
+To understand observer pattern, first you need to understand the subject and observer objects.
+
+The relation between subject and observer can easily be understood as an analogy to magazine subscription.
+
+* A magazine publisher(subject) is in the business and publishes magazines (data).
+* If you(user of data/observer) are interested in the magazine you subscribe(register), and if a new edition is published it gets delivered to you.
+* If you unsubscribe(unregister) you stop getting new editions.
+* Publisher doesn’t know who you are and how you use the magazine, it just delivers it to you because you are a subscriber(loose coupling).
+
+###Definition:
+The Observer Pattern defines a one to many dependency between objects so that one object changes state, all of its dependents are notified and updated automatically.
+###Explanation:
+* One to many dependency is between Subject(One) and Observer(Many).
+* There is dependency as Observers themselves don’t have access to data. They are dependent on Subject to provide them data.
+
+###Class diagram:
+
+
+* Here Observer and Subject are interfaces(can be any abstract super type not necessarily java interface).
+* All observers who need the data need to implement observer interface.
+* notify() method in observer interface defines the action to be taken when the subject provides it data.
+* The subject maintains an observerCollection which is simply the list of currently registered(subscribed) observers.
+* registerObserver(observer) and unregisterObserver(observer) are methods to add and remove observers respectively.
+* notifyObservers() is called when the data is changed and the observers need to be supplied with new data.
+
+###Advantages:
+Provides a loosely coupled design between objects that interact. Loosely coupled objects are flexible with changing requirements. Here loose coupling means that the interacting objects should have less information about each other.
+
+Observer pattern provides this loose coupling as:
+
+* Subject only knows that observer implement Observer interface.Nothing more.
+* There is no need to modify Subject to add or remove observers.
+* We can reuse subject and observer classes independently of each other.
+###Disadvantages:
+
+* Memory leaks caused by Lapsed listener problem because of explicit register and unregistering of observers.
+
+###When to use this pattern?
+You should consider using this pattern in your application when multiple objects are dependent on the state of one object as it provides a neat and well tested design for the same.
+
+###Real Life Uses:
+
+* It is heavily used in GUI toolkits and event listener. In java the button(subject) and onClickListener(observer) are modelled with observer pattern.
+* Social media, RSS feeds, email subscription in which you have the option to follow or subscribe and you receive latest notification.
+* All users of an app on play store gets notified if there is an update.
\ No newline at end of file
diff --git a/src/main/java/com/shenyy/dp/observer/assets/o2.png b/src/main/java/com/shenyy/dp/observer/assets/o2.png
new file mode 100644
index 0000000..f886196
Binary files /dev/null and b/src/main/java/com/shenyy/dp/observer/assets/o2.png differ
diff --git a/src/main/java/com/shenyy/dp/observer/chatgpt/CurrentConditionsDisplay.java b/src/main/java/com/shenyy/dp/observer/chatgpt/CurrentConditionsDisplay.java
new file mode 100644
index 0000000..fa466e0
--- /dev/null
+++ b/src/main/java/com/shenyy/dp/observer/chatgpt/CurrentConditionsDisplay.java
@@ -0,0 +1,22 @@
+package com.shenyy.dp.observer.chatgpt;
+
+public class CurrentConditionsDisplay implements Observer{
+ private float temperature;
+ private float humidity;
+ private Subject weatherData;
+
+ public CurrentConditionsDisplay(Subject weatherData) {
+ this.weatherData = weatherData;
+ weatherData.registerObserver(this);
+ }
+
+ public void update(float temperature, float humidity, float pressure) {
+ this.temperature = temperature;
+ this.humidity = humidity;
+ display();
+ }
+
+ public void display() {
+ System.out.println("Current conditions: " + temperature + "F degrees and " + humidity + "% humidity");
+ }
+}
diff --git a/src/main/java/com/shenyy/dp/observer/chatgpt/Observer.java b/src/main/java/com/shenyy/dp/observer/chatgpt/Observer.java
new file mode 100644
index 0000000..6be041a
--- /dev/null
+++ b/src/main/java/com/shenyy/dp/observer/chatgpt/Observer.java
@@ -0,0 +1,5 @@
+package com.shenyy.dp.observer.chatgpt;
+
+public interface Observer {
+ public void update(float temp, float humidity, float pressure);
+}
diff --git a/src/main/java/com/shenyy/dp/observer/chatgpt/ObserverExample.java b/src/main/java/com/shenyy/dp/observer/chatgpt/ObserverExample.java
new file mode 100644
index 0000000..1dd7a6c
--- /dev/null
+++ b/src/main/java/com/shenyy/dp/observer/chatgpt/ObserverExample.java
@@ -0,0 +1,9 @@
+package com.shenyy.dp.observer.chatgpt;
+
+public class ObserverExample {
+ public static void main(String[] args) {
+ WeatherData weatherData = new WeatherData();
+ CurrentConditionsDisplay currentDisplay = new CurrentConditionsDisplay(weatherData);
+ weatherData.setMeasurements(80, 65, 30.4f);
+ }
+}
diff --git a/src/main/java/com/shenyy/dp/observer/chatgpt/Subject.java b/src/main/java/com/shenyy/dp/observer/chatgpt/Subject.java
new file mode 100644
index 0000000..4ed830d
--- /dev/null
+++ b/src/main/java/com/shenyy/dp/observer/chatgpt/Subject.java
@@ -0,0 +1,9 @@
+package com.shenyy.dp.observer.chatgpt;
+
+public interface Subject {
+ void registerObserver(Observer o);
+
+ void removeObserver(Observer o);
+
+ void notifyObservers();
+}
diff --git a/src/main/java/com/shenyy/dp/observer/chatgpt/WeatherData.java b/src/main/java/com/shenyy/dp/observer/chatgpt/WeatherData.java
new file mode 100644
index 0000000..a069f86
--- /dev/null
+++ b/src/main/java/com/shenyy/dp/observer/chatgpt/WeatherData.java
@@ -0,0 +1,44 @@
+package com.shenyy.dp.observer.chatgpt;
+
+import java.util.ArrayList;
+import java.util.List;
+
+public class WeatherData implements Subject {
+ private List observers;
+ private float temperature;
+ private float humidity;
+ private float pressure;
+
+ public WeatherData() {
+ observers = new ArrayList<>();
+ }
+
+ @Override
+ public void registerObserver(Observer o) {
+ observers.add(o);
+ }
+
+ @Override
+ public void removeObserver(Observer o) {
+ observers.remove(o);
+ }
+
+ @Override
+ public void notifyObservers() {
+ for (Observer observer :
+ observers) {
+ observer.update(temperature, humidity, pressure);
+ }
+ }
+
+ public void measurementsChanged() {
+ notifyObservers();
+ }
+
+ public void setMeasurements(float temperature, float humidity, float pressure) {
+ this.temperature = temperature;
+ this.humidity = humidity;
+ this.pressure = pressure;
+ measurementsChanged();
+ }
+}
diff --git a/src/main/java/com/mashibing/dp/observer/v1/Main1.java b/src/main/java/com/shenyy/dp/observer/example01/v1/Main1.java
similarity index 82%
rename from src/main/java/com/mashibing/dp/observer/v1/Main1.java
rename to src/main/java/com/shenyy/dp/observer/example01/v1/Main1.java
index c5c57b1..767d0de 100644
--- a/src/main/java/com/mashibing/dp/observer/v1/Main1.java
+++ b/src/main/java/com/shenyy/dp/observer/example01/v1/Main1.java
@@ -1,4 +1,4 @@
-package com.mashibing.dp.observer.v1;
+package com.shenyy.dp.observer.example01.v1;
/**
* 披着面向对象外衣的面向过程
diff --git a/src/main/java/com/mashibing/dp/observer/v10/readme b/src/main/java/com/shenyy/dp/observer/example01/v10/readme
similarity index 100%
rename from src/main/java/com/mashibing/dp/observer/v10/readme
rename to src/main/java/com/shenyy/dp/observer/example01/v10/readme
diff --git a/src/main/java/com/mashibing/dp/observer/v11/readme b/src/main/java/com/shenyy/dp/observer/example01/v11/readme
similarity index 100%
rename from src/main/java/com/mashibing/dp/observer/v11/readme
rename to src/main/java/com/shenyy/dp/observer/example01/v11/readme
diff --git a/src/main/java/com/mashibing/dp/observer/v2/Main.java b/src/main/java/com/shenyy/dp/observer/example01/v2/Main.java
similarity index 93%
rename from src/main/java/com/mashibing/dp/observer/v2/Main.java
rename to src/main/java/com/shenyy/dp/observer/example01/v2/Main.java
index b3a97f3..966ea9c 100644
--- a/src/main/java/com/mashibing/dp/observer/v2/Main.java
+++ b/src/main/java/com/shenyy/dp/observer/example01/v2/Main.java
@@ -1,4 +1,4 @@
-package com.mashibing.dp.observer.v2;
+package com.shenyy.dp.observer.example01.v2;
/**
* 面向对象的傻等
diff --git a/src/main/java/com/mashibing/dp/observer/v3/Main.java b/src/main/java/com/shenyy/dp/observer/example01/v3/Main.java
similarity index 91%
rename from src/main/java/com/mashibing/dp/observer/v3/Main.java
rename to src/main/java/com/shenyy/dp/observer/example01/v3/Main.java
index 5a1e543..1f74e8c 100644
--- a/src/main/java/com/mashibing/dp/observer/v3/Main.java
+++ b/src/main/java/com/shenyy/dp/observer/example01/v3/Main.java
@@ -1,4 +1,4 @@
-package com.mashibing.dp.observer.v3;
+package com.shenyy.dp.observer.example01.v3;
/**
* 加入观察者
diff --git a/src/main/java/com/mashibing/dp/observer/v4/Main.java b/src/main/java/com/shenyy/dp/observer/example01/v4/Main.java
similarity index 94%
rename from src/main/java/com/mashibing/dp/observer/v4/Main.java
rename to src/main/java/com/shenyy/dp/observer/example01/v4/Main.java
index a2e998a..deb3812 100644
--- a/src/main/java/com/mashibing/dp/observer/v4/Main.java
+++ b/src/main/java/com/shenyy/dp/observer/example01/v4/Main.java
@@ -1,4 +1,4 @@
-package com.mashibing.dp.observer.v4;
+package com.shenyy.dp.observer.example01.v4;
/**
* 加入多个观察者
diff --git a/src/main/java/com/mashibing/dp/observer/v5/Main.java b/src/main/java/com/shenyy/dp/observer/example01/v5/Main.java
similarity index 96%
rename from src/main/java/com/mashibing/dp/observer/v5/Main.java
rename to src/main/java/com/shenyy/dp/observer/example01/v5/Main.java
index 8e64f1f..c04241f 100644
--- a/src/main/java/com/mashibing/dp/observer/v5/Main.java
+++ b/src/main/java/com/shenyy/dp/observer/example01/v5/Main.java
@@ -1,4 +1,4 @@
-package com.mashibing.dp.observer.v5;
+package com.shenyy.dp.observer.example01.v5;
import java.util.ArrayList;
import java.util.List;
diff --git a/src/main/java/com/mashibing/dp/observer/v6/Main.java b/src/main/java/com/shenyy/dp/observer/example01/v6/Main.java
similarity index 97%
rename from src/main/java/com/mashibing/dp/observer/v6/Main.java
rename to src/main/java/com/shenyy/dp/observer/example01/v6/Main.java
index 1420d1c..05c5f1f 100644
--- a/src/main/java/com/mashibing/dp/observer/v6/Main.java
+++ b/src/main/java/com/shenyy/dp/observer/example01/v6/Main.java
@@ -1,4 +1,4 @@
-package com.mashibing.dp.observer.v6;
+package com.shenyy.dp.observer.example01.v6;
import java.util.ArrayList;
import java.util.List;
diff --git a/src/main/java/com/mashibing/dp/observer/v7/Main.java b/src/main/java/com/shenyy/dp/observer/example01/v7/Main.java
similarity index 97%
rename from src/main/java/com/mashibing/dp/observer/v7/Main.java
rename to src/main/java/com/shenyy/dp/observer/example01/v7/Main.java
index 5270c5d..9dff6a2 100644
--- a/src/main/java/com/mashibing/dp/observer/v7/Main.java
+++ b/src/main/java/com/shenyy/dp/observer/example01/v7/Main.java
@@ -1,4 +1,4 @@
-package com.mashibing.dp.observer.v7;
+package com.shenyy.dp.observer.example01.v7;
import java.util.ArrayList;
import java.util.List;
diff --git a/src/main/java/com/mashibing/dp/observer/v8/Main.java b/src/main/java/com/shenyy/dp/observer/example01/v8/Main.java
similarity index 97%
rename from src/main/java/com/mashibing/dp/observer/v8/Main.java
rename to src/main/java/com/shenyy/dp/observer/example01/v8/Main.java
index 2178827..4280f02 100644
--- a/src/main/java/com/mashibing/dp/observer/v8/Main.java
+++ b/src/main/java/com/shenyy/dp/observer/example01/v8/Main.java
@@ -1,4 +1,4 @@
-package com.mashibing.dp.observer.v8;
+package com.shenyy.dp.observer.example01.v8;
import java.util.ArrayList;
import java.util.List;
diff --git a/src/main/java/com/mashibing/dp/observer/v9/Test.java b/src/main/java/com/shenyy/dp/observer/example01/v9/Test.java
similarity index 96%
rename from src/main/java/com/mashibing/dp/observer/v9/Test.java
rename to src/main/java/com/shenyy/dp/observer/example01/v9/Test.java
index 4aed338..5051b22 100644
--- a/src/main/java/com/mashibing/dp/observer/v9/Test.java
+++ b/src/main/java/com/shenyy/dp/observer/example01/v9/Test.java
@@ -1,4 +1,4 @@
-package com.mashibing.dp.observer.v9;
+package com.shenyy.dp.observer.example01.v9;
import java.util.ArrayList;
import java.util.List;
diff --git a/src/main/java/com/mashibing/dp/observer/v9/TestFrame.java b/src/main/java/com/shenyy/dp/observer/example01/v9/TestFrame.java
similarity index 96%
rename from src/main/java/com/mashibing/dp/observer/v9/TestFrame.java
rename to src/main/java/com/shenyy/dp/observer/example01/v9/TestFrame.java
index 9417bd9..7200a3a 100644
--- a/src/main/java/com/mashibing/dp/observer/v9/TestFrame.java
+++ b/src/main/java/com/shenyy/dp/observer/example01/v9/TestFrame.java
@@ -1,4 +1,4 @@
-package com.mashibing.dp.observer.v9;
+package com.shenyy.dp.observer.example01.v9;
import java.awt.Button;
import java.awt.Frame;
diff --git a/src/main/java/com/shenyy/dp/prototype/Description.md b/src/main/java/com/shenyy/dp/prototype/Description.md
new file mode 100644
index 0000000..fe6a1d7
--- /dev/null
+++ b/src/main/java/com/shenyy/dp/prototype/Description.md
@@ -0,0 +1,3 @@
+##Prototype
+
+Prototype pattern is a creational design pattern in software development that is used to instantiate a new object by copying all of the properties of an existing object, creating a distinct object with the same properties. This approach can be faster than creating a new object from scratch and can also be used to implement a deep copy, meaning all the objects referenced within the new object are also copied.
\ No newline at end of file
diff --git a/src/main/java/com/shenyy/dp/prototype/chatgpt/ConcretePrototypeA.java b/src/main/java/com/shenyy/dp/prototype/chatgpt/ConcretePrototypeA.java
new file mode 100644
index 0000000..be692dc
--- /dev/null
+++ b/src/main/java/com/shenyy/dp/prototype/chatgpt/ConcretePrototypeA.java
@@ -0,0 +1,22 @@
+package com.shenyy.dp.prototype.chatgpt;
+
+public class ConcretePrototypeA extends Prototype {
+ private String fieldA;
+
+ public String getFieldA() {
+ return fieldA;
+ }
+
+ public void setFieldA(String fieldA) {
+ this.fieldA = fieldA;
+ }
+
+ public ConcretePrototypeA(String fieldA) {
+ this.fieldA = fieldA;
+ }
+
+ @Override
+ public Prototype clone() {
+ return new ConcretePrototypeA(fieldA);
+ }
+}
diff --git a/src/main/java/com/shenyy/dp/prototype/chatgpt/ConcretePrototypeB.java b/src/main/java/com/shenyy/dp/prototype/chatgpt/ConcretePrototypeB.java
new file mode 100644
index 0000000..94e81cf
--- /dev/null
+++ b/src/main/java/com/shenyy/dp/prototype/chatgpt/ConcretePrototypeB.java
@@ -0,0 +1,14 @@
+package com.shenyy.dp.prototype.chatgpt;
+
+public class ConcretePrototypeB extends Prototype {
+ private int fieldB;
+
+ public ConcretePrototypeB(int fieldB) {
+ this.fieldB = fieldB;
+ }
+
+ @Override
+ public Prototype clone() {
+ return new ConcretePrototypeB(fieldB);
+ }
+}
diff --git a/src/main/java/com/shenyy/dp/prototype/chatgpt/Prototype.java b/src/main/java/com/shenyy/dp/prototype/chatgpt/Prototype.java
new file mode 100644
index 0000000..876ee91
--- /dev/null
+++ b/src/main/java/com/shenyy/dp/prototype/chatgpt/Prototype.java
@@ -0,0 +1,8 @@
+package com.shenyy.dp.prototype.chatgpt;
+
+public abstract class Prototype {
+ public Prototype() {
+ }
+
+ public abstract Prototype clone();
+}
diff --git a/src/main/java/com/shenyy/dp/prototype/chatgpt/PrototypeExample.java b/src/main/java/com/shenyy/dp/prototype/chatgpt/PrototypeExample.java
new file mode 100644
index 0000000..8eb430a
--- /dev/null
+++ b/src/main/java/com/shenyy/dp/prototype/chatgpt/PrototypeExample.java
@@ -0,0 +1,16 @@
+package com.shenyy.dp.prototype.chatgpt;
+
+public class PrototypeExample {
+
+ private static Prototype prototype1;
+
+ public static void main(String[] args) {
+ Prototype prototype;
+ prototype = new ConcretePrototypeA("germination");
+ System.out.println(prototype);
+
+ Prototype prototype1 = prototype.clone();
+ System.out.println(prototype);
+ System.out.println(prototype1);
+ }
+}
diff --git a/src/main/java/com/mashibing/dp/prototype/v1/Test.java b/src/main/java/com/shenyy/dp/prototype/example01/v1/Test.java
similarity index 95%
rename from src/main/java/com/mashibing/dp/prototype/v1/Test.java
rename to src/main/java/com/shenyy/dp/prototype/example01/v1/Test.java
index 0c371c2..afa1963 100644
--- a/src/main/java/com/mashibing/dp/prototype/v1/Test.java
+++ b/src/main/java/com/shenyy/dp/prototype/example01/v1/Test.java
@@ -1,4 +1,4 @@
-package com.mashibing.dp.prototype.v1;
+package com.shenyy.dp.prototype.example01.v1;
/**
* 浅克隆
diff --git a/src/main/java/com/mashibing/dp/prototype/v2/Test.java b/src/main/java/com/shenyy/dp/prototype/example01/v2/Test.java
similarity index 96%
rename from src/main/java/com/mashibing/dp/prototype/v2/Test.java
rename to src/main/java/com/shenyy/dp/prototype/example01/v2/Test.java
index b5ad31a..ed1b80b 100644
--- a/src/main/java/com/mashibing/dp/prototype/v2/Test.java
+++ b/src/main/java/com/shenyy/dp/prototype/example01/v2/Test.java
@@ -1,4 +1,4 @@
-package com.mashibing.dp.prototype.v2;
+package com.shenyy.dp.prototype.example01.v2;
/**
* 深克隆的处理
diff --git a/src/main/java/com/mashibing/dp/prototype/v3/Test.java b/src/main/java/com/shenyy/dp/prototype/example01/v3/Test.java
similarity index 96%
rename from src/main/java/com/mashibing/dp/prototype/v3/Test.java
rename to src/main/java/com/shenyy/dp/prototype/example01/v3/Test.java
index 478f537..360a67f 100644
--- a/src/main/java/com/mashibing/dp/prototype/v3/Test.java
+++ b/src/main/java/com/shenyy/dp/prototype/example01/v3/Test.java
@@ -1,4 +1,4 @@
-package com.mashibing.dp.prototype.v3;
+package com.shenyy.dp.prototype.example01.v3;
/**
* String需要进一步深克隆吗?
diff --git a/src/main/java/com/mashibing/dp/prototype/v4/Test.java b/src/main/java/com/shenyy/dp/prototype/example01/v4/Test.java
similarity index 96%
rename from src/main/java/com/mashibing/dp/prototype/v4/Test.java
rename to src/main/java/com/shenyy/dp/prototype/example01/v4/Test.java
index c29f330..ef2e7d4 100644
--- a/src/main/java/com/mashibing/dp/prototype/v4/Test.java
+++ b/src/main/java/com/shenyy/dp/prototype/example01/v4/Test.java
@@ -1,4 +1,4 @@
-package com.mashibing.dp.prototype.v4;
+package com.shenyy.dp.prototype.example01.v4;
/**
* String需要进一步深克隆吗?
diff --git a/src/main/java/com/shenyy/dp/proxy/Description.md b/src/main/java/com/shenyy/dp/proxy/Description.md
new file mode 100644
index 0000000..37b1a6f
--- /dev/null
+++ b/src/main/java/com/shenyy/dp/proxy/Description.md
@@ -0,0 +1,29 @@
+##Description
+
+Proxy means ‘in place of’, 'representing’ or ‘in place of’ or ‘on behalf of’ are literal meanings of proxy and that directly explains Proxy Design Pattern.
+Proxies are also called surrogates, handles, and wrappers. They are closely related in structure, but not purpose, to Adapters and Decorators.
+
+A real world example can be a cheque or credit card is a proxy for what is in our bank account. It can be used in place of cash, and provides a means of accessing that cash when required. And that’s exactly what the Proxy pattern does – “Controls and manage access to the object they are protecting“.
+
+###Behavior
+As in the decorator pattern, proxies can be chained together. The client and each proxy, believes it is delegating messages to the real server:
+
+
+
+###When to use this pattern?
+Proxy pattern is used when we need to create a wrapper to cover the main object’s complexity from the client.
+
+###Types of proxies
+* ####Remote proxy:
+They are responsible for representing the object located remotely. Talking to the real object might involve marshalling and unmarshalling of data and talking to the remote object. All that logic is encapsulated in these proxies and the client application need not worry about them.
+* ####Virtual proxy:
+These proxies will provide some default and instant results if the real object is supposed to take some time to produce results. These proxies initiate the operation on real objects and provide a default result to the application. Once the real object is done, these proxies push the actual data to the client where it has provided dummy data earlier.
+* ####Protection proxy:
+If an application does not have access to some resource then such proxies will talk to the objects in applications that have access to that resource and then get the result back.
+* ####Smart Proxy:
+A smart proxy provides additional layer of security by interposing specific actions when the object is accessed. An example can be to check if the real object is locked before it is accessed to ensure that no other object can change it.
+
+###
Example
+A very simple real life scenario is our college internet, which restricts few site access. The proxy first checks the host you are connecting to, if it is not part of restricted site list, then it connects to the real internet. This example is based on Protection proxies.
+
+see this example in the _'/example/...'_
diff --git a/src/main/java/com/shenyy/dp/proxy/assets/UML_Diagram.jpg b/src/main/java/com/shenyy/dp/proxy/assets/UML_Diagram.jpg
new file mode 100644
index 0000000..14dcd89
Binary files /dev/null and b/src/main/java/com/shenyy/dp/proxy/assets/UML_Diagram.jpg differ
diff --git a/src/main/java/com/shenyy/dp/proxy/chatgpt/Client.java b/src/main/java/com/shenyy/dp/proxy/chatgpt/Client.java
new file mode 100644
index 0000000..3a65f76
--- /dev/null
+++ b/src/main/java/com/shenyy/dp/proxy/chatgpt/Client.java
@@ -0,0 +1,18 @@
+package com.shenyy.dp.proxy.chatgpt;
+
+public class Client {
+ public static void main(String[] args) {
+ Internet internet = new ProxyInternet();
+ try {
+ internet.connectTo("google.com");
+ } catch (Exception e) {
+ System.out.println(e.getMessage());
+ }
+
+ try {
+ internet.connectTo("baidu.com");
+ } catch (Exception e) {
+ System.out.println(e.getMessage());
+ }
+ }
+}
diff --git a/src/main/java/com/shenyy/dp/proxy/chatgpt/Internet.java b/src/main/java/com/shenyy/dp/proxy/chatgpt/Internet.java
new file mode 100644
index 0000000..90509af
--- /dev/null
+++ b/src/main/java/com/shenyy/dp/proxy/chatgpt/Internet.java
@@ -0,0 +1,5 @@
+package com.shenyy.dp.proxy.chatgpt;
+
+public interface Internet {
+ public void connectTo(String serverHost) throws Exception;
+}
diff --git a/src/main/java/com/shenyy/dp/proxy/chatgpt/ProxyInternet.java b/src/main/java/com/shenyy/dp/proxy/chatgpt/ProxyInternet.java
new file mode 100644
index 0000000..5723dbc
--- /dev/null
+++ b/src/main/java/com/shenyy/dp/proxy/chatgpt/ProxyInternet.java
@@ -0,0 +1,24 @@
+package com.shenyy.dp.proxy.chatgpt;
+
+import java.util.ArrayList;
+import java.util.List;
+
+public class ProxyInternet implements Internet {
+ private Internet internet = new RealInternet();
+
+ private static List bannedSites = new ArrayList<>();
+
+ static {
+ bannedSites.add("facebook.com");
+ bannedSites.add("google.com");
+ }
+
+ @Override
+ public void connectTo(String serverHost) throws Exception {
+ if (bannedSites.contains(serverHost)) {
+ throw new Exception("Access Denied");
+ }
+
+ internet.connectTo(serverHost);
+ }
+}
diff --git a/src/main/java/com/shenyy/dp/proxy/chatgpt/RealInternet.java b/src/main/java/com/shenyy/dp/proxy/chatgpt/RealInternet.java
new file mode 100644
index 0000000..465278a
--- /dev/null
+++ b/src/main/java/com/shenyy/dp/proxy/chatgpt/RealInternet.java
@@ -0,0 +1,8 @@
+package com.shenyy.dp.proxy.chatgpt;
+
+public class RealInternet implements Internet {
+ @Override
+ public void connectTo(String serverHost) throws Exception {
+ System.out.println("Connecting to " + serverHost);
+ }
+}
diff --git a/src/main/java/com/mashibing/dp/proxy/v01/Tank.java b/src/main/java/com/shenyy/dp/proxy/example01/v01/Tank.java
similarity index 91%
rename from src/main/java/com/mashibing/dp/proxy/v01/Tank.java
rename to src/main/java/com/shenyy/dp/proxy/example01/v01/Tank.java
index fb9ed10..40d8158 100644
--- a/src/main/java/com/mashibing/dp/proxy/v01/Tank.java
+++ b/src/main/java/com/shenyy/dp/proxy/example01/v01/Tank.java
@@ -1,4 +1,4 @@
-package com.mashibing.dp.proxy.v01;
+package com.shenyy.dp.proxy.example01.v01;
import java.util.Random;
diff --git a/src/main/java/com/mashibing/dp/proxy/v02/Tank.java b/src/main/java/com/shenyy/dp/proxy/example01/v02/Tank.java
similarity index 94%
rename from src/main/java/com/mashibing/dp/proxy/v02/Tank.java
rename to src/main/java/com/shenyy/dp/proxy/example01/v02/Tank.java
index 260e28c..c41d270 100644
--- a/src/main/java/com/mashibing/dp/proxy/v02/Tank.java
+++ b/src/main/java/com/shenyy/dp/proxy/example01/v02/Tank.java
@@ -1,4 +1,4 @@
-package com.mashibing.dp.proxy.v02;
+package com.shenyy.dp.proxy.example01.v02;
import java.util.Random;
diff --git a/src/main/java/com/mashibing/dp/proxy/v03/Tank.java b/src/main/java/com/shenyy/dp/proxy/example01/v03/Tank.java
similarity index 94%
rename from src/main/java/com/mashibing/dp/proxy/v03/Tank.java
rename to src/main/java/com/shenyy/dp/proxy/example01/v03/Tank.java
index dba96b7..9c6d440 100644
--- a/src/main/java/com/mashibing/dp/proxy/v03/Tank.java
+++ b/src/main/java/com/shenyy/dp/proxy/example01/v03/Tank.java
@@ -1,4 +1,4 @@
-package com.mashibing.dp.proxy.v03;
+package com.shenyy.dp.proxy.example01.v03;
import java.util.Random;
diff --git a/src/main/java/com/mashibing/dp/proxy/v04/Tank.java b/src/main/java/com/shenyy/dp/proxy/example01/v04/Tank.java
similarity index 95%
rename from src/main/java/com/mashibing/dp/proxy/v04/Tank.java
rename to src/main/java/com/shenyy/dp/proxy/example01/v04/Tank.java
index 618dd91..7676258 100644
--- a/src/main/java/com/mashibing/dp/proxy/v04/Tank.java
+++ b/src/main/java/com/shenyy/dp/proxy/example01/v04/Tank.java
@@ -1,4 +1,4 @@
-package com.mashibing.dp.proxy.v04;
+package com.shenyy.dp.proxy.example01.v04;
import java.util.Random;
diff --git a/src/main/java/com/mashibing/dp/proxy/v05/Tank.java b/src/main/java/com/shenyy/dp/proxy/example01/v05/Tank.java
similarity index 96%
rename from src/main/java/com/mashibing/dp/proxy/v05/Tank.java
rename to src/main/java/com/shenyy/dp/proxy/example01/v05/Tank.java
index 44e4fa5..3c408e6 100644
--- a/src/main/java/com/mashibing/dp/proxy/v05/Tank.java
+++ b/src/main/java/com/shenyy/dp/proxy/example01/v05/Tank.java
@@ -1,4 +1,4 @@
-package com.mashibing.dp.proxy.v05;
+package com.shenyy.dp.proxy.example01.v05;
import java.util.Random;
diff --git a/src/main/java/com/mashibing/dp/proxy/v06/Tank.java b/src/main/java/com/shenyy/dp/proxy/example01/v06/Tank.java
similarity index 96%
rename from src/main/java/com/mashibing/dp/proxy/v06/Tank.java
rename to src/main/java/com/shenyy/dp/proxy/example01/v06/Tank.java
index 7f5095a..45a110b 100644
--- a/src/main/java/com/mashibing/dp/proxy/v06/Tank.java
+++ b/src/main/java/com/shenyy/dp/proxy/example01/v06/Tank.java
@@ -1,4 +1,4 @@
-package com.mashibing.dp.proxy.v06;
+package com.shenyy.dp.proxy.example01.v06;
import java.util.Random;
diff --git a/src/main/java/com/mashibing/dp/proxy/v07/Tank.java b/src/main/java/com/shenyy/dp/proxy/example01/v07/Tank.java
similarity index 97%
rename from src/main/java/com/mashibing/dp/proxy/v07/Tank.java
rename to src/main/java/com/shenyy/dp/proxy/example01/v07/Tank.java
index 928f6c9..219040a 100644
--- a/src/main/java/com/mashibing/dp/proxy/v07/Tank.java
+++ b/src/main/java/com/shenyy/dp/proxy/example01/v07/Tank.java
@@ -1,4 +1,4 @@
-package com.mashibing.dp.proxy.v07;
+package com.shenyy.dp.proxy.example01.v07;
import java.util.Random;
diff --git a/src/main/java/com/mashibing/dp/proxy/v08/Tank.java b/src/main/java/com/shenyy/dp/proxy/example01/v08/Tank.java
similarity index 97%
rename from src/main/java/com/mashibing/dp/proxy/v08/Tank.java
rename to src/main/java/com/shenyy/dp/proxy/example01/v08/Tank.java
index b9aa038..f44c8d3 100644
--- a/src/main/java/com/mashibing/dp/proxy/v08/Tank.java
+++ b/src/main/java/com/shenyy/dp/proxy/example01/v08/Tank.java
@@ -1,4 +1,4 @@
-package com.mashibing.dp.proxy.v08;
+package com.shenyy.dp.proxy.example01.v08;
import java.lang.reflect.InvocationHandler;
diff --git a/src/main/java/com/mashibing/dp/proxy/v09/Tank.java b/src/main/java/com/shenyy/dp/proxy/example01/v09/Tank.java
similarity index 97%
rename from src/main/java/com/mashibing/dp/proxy/v09/Tank.java
rename to src/main/java/com/shenyy/dp/proxy/example01/v09/Tank.java
index 22879b2..9ff9789 100644
--- a/src/main/java/com/mashibing/dp/proxy/v09/Tank.java
+++ b/src/main/java/com/shenyy/dp/proxy/example01/v09/Tank.java
@@ -1,4 +1,4 @@
-package com.mashibing.dp.proxy.v09;
+package com.shenyy.dp.proxy.example01.v09;
diff --git a/src/main/java/com/mashibing/dp/proxy/v10/Tank.java b/src/main/java/com/shenyy/dp/proxy/example01/v10/Tank.java
similarity index 97%
rename from src/main/java/com/mashibing/dp/proxy/v10/Tank.java
rename to src/main/java/com/shenyy/dp/proxy/example01/v10/Tank.java
index 8bc072f..c362fce 100644
--- a/src/main/java/com/mashibing/dp/proxy/v10/Tank.java
+++ b/src/main/java/com/shenyy/dp/proxy/example01/v10/Tank.java
@@ -1,11 +1,10 @@
-package com.mashibing.dp.proxy.v10;
+package com.shenyy.dp.proxy.example01.v10;
import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;
-import java.util.Arrays;
import java.util.Random;
/**
diff --git a/src/main/java/com/shenyy/dp/singleton/chatgpt/Description.md b/src/main/java/com/shenyy/dp/singleton/chatgpt/Description.md
new file mode 100644
index 0000000..eb33cba
--- /dev/null
+++ b/src/main/java/com/shenyy/dp/singleton/chatgpt/Description.md
@@ -0,0 +1,5 @@
+##Singleton
+
+Singleton pattern is a creational design pattern in software development that restricts a class to have only one instance and provides a global point of access to that instance. This ensures that the class only has one instance across the entire application, making it easy to manage and maintain the state of the object.
+
+In this example, the Singleton class has a private constructor to prevent external classes from creating multiple instances of the class. The getInstance method is used to access the singleton instance and creates the instance if it doesn't exist. The method is also synchronized to ensure that it is thread-safe.
\ No newline at end of file
diff --git a/src/main/java/com/shenyy/dp/singleton/chatgpt/Singleton.java b/src/main/java/com/shenyy/dp/singleton/chatgpt/Singleton.java
new file mode 100644
index 0000000..1a5df37
--- /dev/null
+++ b/src/main/java/com/shenyy/dp/singleton/chatgpt/Singleton.java
@@ -0,0 +1,24 @@
+package com.shenyy.dp.singleton.chatgpt;
+
+public class Singleton {
+ private String windowName;
+
+ public String getWindowName() {
+ return windowName;
+ }
+
+ public void setWindowName(String windowName) {
+ this.windowName = windowName;
+ }
+
+ private static Singleton instance;
+
+ private Singleton() {}
+
+ public static synchronized Singleton getInstance(){
+ if(instance == null){
+ instance = new Singleton();
+ }
+ return instance;
+ }
+}
diff --git a/src/main/java/com/shenyy/dp/singleton/chatgpt/SingletonExample.java b/src/main/java/com/shenyy/dp/singleton/chatgpt/SingletonExample.java
new file mode 100644
index 0000000..596e24e
--- /dev/null
+++ b/src/main/java/com/shenyy/dp/singleton/chatgpt/SingletonExample.java
@@ -0,0 +1,15 @@
+package com.shenyy.dp.singleton.chatgpt;
+
+public class SingletonExample {
+ public static void main(String[] args) {
+ Singleton singleton = Singleton.getInstance();
+ Singleton.getInstance();
+ singleton.setWindowName("window");
+ System.out.println(singleton);
+
+ Singleton singleton1 = Singleton.getInstance();
+ singleton1.setWindowName("new window");
+ System.out.println(singleton.getWindowName());
+ System.out.println(singleton1.getWindowName());
+ }
+}
diff --git a/src/main/java/com/mashibing/dp/singleton/Main.java b/src/main/java/com/shenyy/dp/singleton/example01/Main.java
similarity index 73%
rename from src/main/java/com/mashibing/dp/singleton/Main.java
rename to src/main/java/com/shenyy/dp/singleton/example01/Main.java
index 5900c0d..743839f 100644
--- a/src/main/java/com/mashibing/dp/singleton/Main.java
+++ b/src/main/java/com/shenyy/dp/singleton/example01/Main.java
@@ -1,4 +1,4 @@
-package com.mashibing.dp.singleton;
+package com.shenyy.dp.singleton.example01;
public class Main {
diff --git a/src/main/java/com/mashibing/dp/singleton/Mgr01.java b/src/main/java/com/shenyy/dp/singleton/example01/Mgr01.java
similarity index 94%
rename from src/main/java/com/mashibing/dp/singleton/Mgr01.java
rename to src/main/java/com/shenyy/dp/singleton/example01/Mgr01.java
index b0010c9..75f284c 100644
--- a/src/main/java/com/mashibing/dp/singleton/Mgr01.java
+++ b/src/main/java/com/shenyy/dp/singleton/example01/Mgr01.java
@@ -1,4 +1,4 @@
-package com.mashibing.dp.singleton;
+package com.shenyy.dp.singleton.example01;
/**
* 饿汉式
diff --git a/src/main/java/com/mashibing/dp/singleton/Mgr02.java b/src/main/java/com/shenyy/dp/singleton/example01/Mgr02.java
similarity index 91%
rename from src/main/java/com/mashibing/dp/singleton/Mgr02.java
rename to src/main/java/com/shenyy/dp/singleton/example01/Mgr02.java
index bbd3f5f..011e89f 100644
--- a/src/main/java/com/mashibing/dp/singleton/Mgr02.java
+++ b/src/main/java/com/shenyy/dp/singleton/example01/Mgr02.java
@@ -1,4 +1,4 @@
-package com.mashibing.dp.singleton;
+package com.shenyy.dp.singleton.example01;
/**
* 跟01是一个意思
diff --git a/src/main/java/com/mashibing/dp/singleton/Mgr03.java b/src/main/java/com/shenyy/dp/singleton/example01/Mgr03.java
similarity index 94%
rename from src/main/java/com/mashibing/dp/singleton/Mgr03.java
rename to src/main/java/com/shenyy/dp/singleton/example01/Mgr03.java
index 26d42f9..7773daf 100644
--- a/src/main/java/com/mashibing/dp/singleton/Mgr03.java
+++ b/src/main/java/com/shenyy/dp/singleton/example01/Mgr03.java
@@ -1,4 +1,4 @@
-package com.mashibing.dp.singleton;
+package com.shenyy.dp.singleton.example01;
/**
* lazy loading
diff --git a/src/main/java/com/mashibing/dp/singleton/Mgr04.java b/src/main/java/com/shenyy/dp/singleton/example01/Mgr04.java
similarity index 95%
rename from src/main/java/com/mashibing/dp/singleton/Mgr04.java
rename to src/main/java/com/shenyy/dp/singleton/example01/Mgr04.java
index 427188d..6a1ac41 100644
--- a/src/main/java/com/mashibing/dp/singleton/Mgr04.java
+++ b/src/main/java/com/shenyy/dp/singleton/example01/Mgr04.java
@@ -1,4 +1,4 @@
-package com.mashibing.dp.singleton;
+package com.shenyy.dp.singleton.example01;
/**
* lazy loading
diff --git a/src/main/java/com/mashibing/dp/singleton/Mgr05.java b/src/main/java/com/shenyy/dp/singleton/example01/Mgr05.java
similarity index 95%
rename from src/main/java/com/mashibing/dp/singleton/Mgr05.java
rename to src/main/java/com/shenyy/dp/singleton/example01/Mgr05.java
index d94254c..d8b5b0d 100644
--- a/src/main/java/com/mashibing/dp/singleton/Mgr05.java
+++ b/src/main/java/com/shenyy/dp/singleton/example01/Mgr05.java
@@ -1,4 +1,4 @@
-package com.mashibing.dp.singleton;
+package com.shenyy.dp.singleton.example01;
/**
* lazy loading
diff --git a/src/main/java/com/mashibing/dp/singleton/Mgr06.java b/src/main/java/com/shenyy/dp/singleton/example01/Mgr06.java
similarity index 96%
rename from src/main/java/com/mashibing/dp/singleton/Mgr06.java
rename to src/main/java/com/shenyy/dp/singleton/example01/Mgr06.java
index 7076a9d..30a9412 100644
--- a/src/main/java/com/mashibing/dp/singleton/Mgr06.java
+++ b/src/main/java/com/shenyy/dp/singleton/example01/Mgr06.java
@@ -1,4 +1,4 @@
-package com.mashibing.dp.singleton;
+package com.shenyy.dp.singleton.example01;
/**
* lazy loading
diff --git a/src/main/java/com/mashibing/dp/singleton/Mgr07.java b/src/main/java/com/shenyy/dp/singleton/example01/Mgr07.java
similarity index 93%
rename from src/main/java/com/mashibing/dp/singleton/Mgr07.java
rename to src/main/java/com/shenyy/dp/singleton/example01/Mgr07.java
index b5f9ce7..5aeac07 100644
--- a/src/main/java/com/mashibing/dp/singleton/Mgr07.java
+++ b/src/main/java/com/shenyy/dp/singleton/example01/Mgr07.java
@@ -1,4 +1,4 @@
-package com.mashibing.dp.singleton;
+package com.shenyy.dp.singleton.example01;
/**
* 静态内部类方式
diff --git a/src/main/java/com/mashibing/dp/singleton/Mgr08.java b/src/main/java/com/shenyy/dp/singleton/example01/Mgr08.java
similarity index 89%
rename from src/main/java/com/mashibing/dp/singleton/Mgr08.java
rename to src/main/java/com/shenyy/dp/singleton/example01/Mgr08.java
index 8e7c841..78b720b 100644
--- a/src/main/java/com/mashibing/dp/singleton/Mgr08.java
+++ b/src/main/java/com/shenyy/dp/singleton/example01/Mgr08.java
@@ -1,4 +1,4 @@
-package com.mashibing.dp.singleton;
+package com.shenyy.dp.singleton.example01;
/**
* 不仅可以解决线程同步,还可以防止反序列化。
diff --git a/src/main/java/com/mashibing/dp/spring/v1/Main.java b/src/main/java/com/shenyy/dp/spring/v1/Main.java
similarity index 91%
rename from src/main/java/com/mashibing/dp/spring/v1/Main.java
rename to src/main/java/com/shenyy/dp/spring/v1/Main.java
index 8918fe8..fab82af 100644
--- a/src/main/java/com/mashibing/dp/spring/v1/Main.java
+++ b/src/main/java/com/shenyy/dp/spring/v1/Main.java
@@ -1,4 +1,4 @@
-package com.mashibing.dp.spring.v1;
+package com.shenyy.dp.spring.v1;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
diff --git a/src/main/java/com/mashibing/dp/spring/v2/Tank.java b/src/main/java/com/shenyy/dp/spring/v1/Tank.java
similarity index 91%
rename from src/main/java/com/mashibing/dp/spring/v2/Tank.java
rename to src/main/java/com/shenyy/dp/spring/v1/Tank.java
index a09ebbc..00690ba 100644
--- a/src/main/java/com/mashibing/dp/spring/v2/Tank.java
+++ b/src/main/java/com/shenyy/dp/spring/v1/Tank.java
@@ -1,4 +1,4 @@
-package com.mashibing.dp.spring.v2;
+package com.shenyy.dp.spring.v1;
diff --git a/src/main/java/com/mashibing/dp/spring/v1/TimeProxy.java b/src/main/java/com/shenyy/dp/spring/v1/TimeProxy.java
similarity index 87%
rename from src/main/java/com/mashibing/dp/spring/v1/TimeProxy.java
rename to src/main/java/com/shenyy/dp/spring/v1/TimeProxy.java
index c54394d..a62ab5a 100644
--- a/src/main/java/com/mashibing/dp/spring/v1/TimeProxy.java
+++ b/src/main/java/com/shenyy/dp/spring/v1/TimeProxy.java
@@ -1,4 +1,4 @@
-package com.mashibing.dp.spring.v1;
+package com.shenyy.dp.spring.v1;
public class TimeProxy {
diff --git a/src/main/java/com/mashibing/dp/spring/v2/Main.java b/src/main/java/com/shenyy/dp/spring/v2/Main.java
similarity index 91%
rename from src/main/java/com/mashibing/dp/spring/v2/Main.java
rename to src/main/java/com/shenyy/dp/spring/v2/Main.java
index 4ff188b..de18885 100644
--- a/src/main/java/com/mashibing/dp/spring/v2/Main.java
+++ b/src/main/java/com/shenyy/dp/spring/v2/Main.java
@@ -1,4 +1,4 @@
-package com.mashibing.dp.spring.v2;
+package com.shenyy.dp.spring.v2;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
diff --git a/src/main/java/com/mashibing/dp/spring/v1/Tank.java b/src/main/java/com/shenyy/dp/spring/v2/Tank.java
similarity index 71%
rename from src/main/java/com/mashibing/dp/spring/v1/Tank.java
rename to src/main/java/com/shenyy/dp/spring/v2/Tank.java
index 65d1c88..2204357 100644
--- a/src/main/java/com/mashibing/dp/spring/v1/Tank.java
+++ b/src/main/java/com/shenyy/dp/spring/v2/Tank.java
@@ -1,10 +1,7 @@
-package com.mashibing.dp.spring.v1;
+package com.shenyy.dp.spring.v2;
-import java.lang.reflect.InvocationHandler;
-import java.lang.reflect.Method;
-import java.lang.reflect.Proxy;
import java.util.Random;
/**
diff --git a/src/main/java/com/mashibing/dp/spring/v2/TimeProxy.java b/src/main/java/com/shenyy/dp/spring/v2/TimeProxy.java
similarity index 93%
rename from src/main/java/com/mashibing/dp/spring/v2/TimeProxy.java
rename to src/main/java/com/shenyy/dp/spring/v2/TimeProxy.java
index cd05ef1..dc15648 100644
--- a/src/main/java/com/mashibing/dp/spring/v2/TimeProxy.java
+++ b/src/main/java/com/shenyy/dp/spring/v2/TimeProxy.java
@@ -1,4 +1,4 @@
-package com.mashibing.dp.spring.v2;
+package com.shenyy.dp.spring.v2;
import org.aspectj.lang.annotation.After;
import org.aspectj.lang.annotation.Aspect;
diff --git a/src/main/java/com/shenyy/dp/state/Description.md b/src/main/java/com/shenyy/dp/state/Description.md
new file mode 100644
index 0000000..f202e81
--- /dev/null
+++ b/src/main/java/com/shenyy/dp/state/Description.md
@@ -0,0 +1,22 @@
+##Description
+The state pattern is one of the behavioral design patterns. A state design pattern is used when an Object changes its behavior based on its internal state. If we have to change the behavior of an object based on its state, we can have a state variable in the Object and use the if-else condition block to perform different actions based on the state. The state pattern is used to provide a systematic and lose-coupled way to achieve this through Context and State implementations.
+
+
+
+* **Context**: Defines an interface for clients to interact. It maintains references to concrete state objects which may be used to define the current state of objects.
+* **State**: Defines interface for declaring what each concrete state should do.
+* **ConcreteState**: Provides the implementation for methods defined in State.
+
+**Example of State Design Pattern** In the below example, we have implemented a mobile state scenario. With respect to alerts, a mobile can be in different states. For example, vibration and silence. Based on this alert state, the behavior of the mobile changes when an alert is to be done.
+
+###
Advantages of State Design Pattern
+
+* With State pattern, the benefits of implementing polymorphic behavior are evident, and it is also easier to add states to support additional behavior.
+* In the State design pattern, an object’s behavior is the result of the function of its state, and the behavior gets changed at runtime depending on the state. This removes the dependency on the if/else or switch/case conditional logic. For example, in the TV remote scenario, we could have also implemented the behavior by simply writing one class and method that will ask for a parameter and perform an action (switch the TV on/off) with an if/else block.
+* The State design pattern also improves Cohesion since state-specific behaviors are aggregated into the ConcreteState classes, which are placed in one location in the code.
+* It can make your code easier to read. Your code may be simpler to comprehend if the behavior is divided into several states, with each state having a distinct name that is both obvious and descriptive.
+* You may find it helpful to follow the Single Responsibility Principle (SRP). According to the SRP, a class should only have one cause to modify. You may guarantee that each state has a clear and distinct duty by encapsulating the behavior in multiple states, which can make your code easier to maintain and alter.
+
+###
Disadvantages of State Design Pattern
+
+* The State design pattern can be used when we need to change the state of the object at runtime by inputting into it different subclasses of some State base class. This circumstance is an advantage and disadvantage at the same time because we have a clear separate State class with some logic and on the other hand the number of classes grows up.
\ No newline at end of file
diff --git a/src/main/java/com/shenyy/dp/state/assets/State-Design-Pattern-Diagram.png b/src/main/java/com/shenyy/dp/state/assets/State-Design-Pattern-Diagram.png
new file mode 100644
index 0000000..bfa8f62
Binary files /dev/null and b/src/main/java/com/shenyy/dp/state/assets/State-Design-Pattern-Diagram.png differ
diff --git a/src/main/java/com/shenyy/dp/state/chatgpt/Context.java b/src/main/java/com/shenyy/dp/state/chatgpt/Context.java
new file mode 100644
index 0000000..a36090c
--- /dev/null
+++ b/src/main/java/com/shenyy/dp/state/chatgpt/Context.java
@@ -0,0 +1,17 @@
+package com.shenyy.dp.state.chatgpt;
+
+public class Context {
+ private State state;
+
+ public Context() {
+ state = null;
+ }
+
+ public State getState() {
+ return state;
+ }
+
+ public void setState(State state) {
+ this.state = state;
+ }
+}
diff --git a/src/main/java/com/shenyy/dp/state/chatgpt/StartState.java b/src/main/java/com/shenyy/dp/state/chatgpt/StartState.java
new file mode 100644
index 0000000..c5bd26c
--- /dev/null
+++ b/src/main/java/com/shenyy/dp/state/chatgpt/StartState.java
@@ -0,0 +1,14 @@
+package com.shenyy.dp.state.chatgpt;
+
+public class StartState implements State{
+ @Override
+ public void handle(Context context) {
+ System.out.println("Start state");
+ context.setState(this);
+ }
+
+ @Override
+ public String toString() {
+ return "StartState{}";
+ }
+}
diff --git a/src/main/java/com/shenyy/dp/state/chatgpt/State.java b/src/main/java/com/shenyy/dp/state/chatgpt/State.java
new file mode 100644
index 0000000..63cfdde
--- /dev/null
+++ b/src/main/java/com/shenyy/dp/state/chatgpt/State.java
@@ -0,0 +1,5 @@
+package com.shenyy.dp.state.chatgpt;
+
+public interface State {
+ void handle(Context context);
+}
diff --git a/src/main/java/com/shenyy/dp/state/chatgpt/StateExample.java b/src/main/java/com/shenyy/dp/state/chatgpt/StateExample.java
new file mode 100644
index 0000000..d1fe6ed
--- /dev/null
+++ b/src/main/java/com/shenyy/dp/state/chatgpt/StateExample.java
@@ -0,0 +1,17 @@
+package com.shenyy.dp.state.chatgpt;
+
+public class StateExample {
+ public static void main(String[] args) {
+ Context context = new Context();
+
+ StartState startState = new StartState();
+ startState.handle(context);//state.handle
+
+ System.out.println(context.getState().toString());
+
+ StopState stopState = new StopState();
+ stopState.handle(context);
+
+ System.out.println(context.getState().toString());
+ }
+}
diff --git a/src/main/java/com/shenyy/dp/state/chatgpt/StopState.java b/src/main/java/com/shenyy/dp/state/chatgpt/StopState.java
new file mode 100644
index 0000000..9f4188f
--- /dev/null
+++ b/src/main/java/com/shenyy/dp/state/chatgpt/StopState.java
@@ -0,0 +1,14 @@
+package com.shenyy.dp.state.chatgpt;
+
+public class StopState implements State{
+ @Override
+ public void handle(Context context) {
+ System.out.println("Stop state");
+ context.setState(this);
+ }
+
+ @Override
+ public String toString() {
+ return "StopState{}";
+ }
+}
diff --git a/src/main/java/com/mashibing/dp/state/readme b/src/main/java/com/shenyy/dp/state/example01/readme
similarity index 100%
rename from src/main/java/com/mashibing/dp/state/readme
rename to src/main/java/com/shenyy/dp/state/example01/readme
diff --git a/src/main/java/com/shenyy/dp/state/example01/thread/Action.java b/src/main/java/com/shenyy/dp/state/example01/thread/Action.java
new file mode 100644
index 0000000..1b26b49
--- /dev/null
+++ b/src/main/java/com/shenyy/dp/state/example01/thread/Action.java
@@ -0,0 +1,5 @@
+package com.shenyy.dp.state.example01.thread;
+
+public class Action {
+ String msg;
+}
diff --git a/src/main/java/com/mashibing/dp/state/thread/NewState.java b/src/main/java/com/shenyy/dp/state/example01/thread/NewState.java
similarity index 86%
rename from src/main/java/com/mashibing/dp/state/thread/NewState.java
rename to src/main/java/com/shenyy/dp/state/example01/thread/NewState.java
index 10272df..4995309 100644
--- a/src/main/java/com/mashibing/dp/state/thread/NewState.java
+++ b/src/main/java/com/shenyy/dp/state/example01/thread/NewState.java
@@ -1,4 +1,4 @@
-package com.mashibing.dp.state.thread;
+package com.shenyy.dp.state.example01.thread;
public class NewState extends ThreadState_ {
private Thread_ t;
diff --git a/src/main/java/com/mashibing/dp/state/thread/RunningState.java b/src/main/java/com/shenyy/dp/state/example01/thread/RunningState.java
similarity index 83%
rename from src/main/java/com/mashibing/dp/state/thread/RunningState.java
rename to src/main/java/com/shenyy/dp/state/example01/thread/RunningState.java
index f2ab05e..0c3e48c 100644
--- a/src/main/java/com/mashibing/dp/state/thread/RunningState.java
+++ b/src/main/java/com/shenyy/dp/state/example01/thread/RunningState.java
@@ -1,4 +1,4 @@
-package com.mashibing.dp.state.thread;
+package com.shenyy.dp.state.example01.thread;
public class RunningState extends ThreadState_ {
private Thread_ t;
diff --git a/src/main/java/com/mashibing/dp/state/thread/TerminatedState.java b/src/main/java/com/shenyy/dp/state/example01/thread/TerminatedState.java
similarity index 83%
rename from src/main/java/com/mashibing/dp/state/thread/TerminatedState.java
rename to src/main/java/com/shenyy/dp/state/example01/thread/TerminatedState.java
index cee981d..74cf47d 100644
--- a/src/main/java/com/mashibing/dp/state/thread/TerminatedState.java
+++ b/src/main/java/com/shenyy/dp/state/example01/thread/TerminatedState.java
@@ -1,4 +1,4 @@
-package com.mashibing.dp.state.thread;
+package com.shenyy.dp.state.example01.thread;
public class TerminatedState extends ThreadState_ {
private Thread_ t;
diff --git a/src/main/java/com/mashibing/dp/state/thread/ThreadState_.java b/src/main/java/com/shenyy/dp/state/example01/thread/ThreadState_.java
similarity index 69%
rename from src/main/java/com/mashibing/dp/state/thread/ThreadState_.java
rename to src/main/java/com/shenyy/dp/state/example01/thread/ThreadState_.java
index d2e062e..7663250 100644
--- a/src/main/java/com/mashibing/dp/state/thread/ThreadState_.java
+++ b/src/main/java/com/shenyy/dp/state/example01/thread/ThreadState_.java
@@ -1,4 +1,4 @@
-package com.mashibing.dp.state.thread;
+package com.shenyy.dp.state.example01.thread;
public abstract class ThreadState_ {
abstract void move(Action input);
diff --git a/src/main/java/com/mashibing/dp/state/thread/Thread_.java b/src/main/java/com/shenyy/dp/state/example01/thread/Thread_.java
similarity index 77%
rename from src/main/java/com/mashibing/dp/state/thread/Thread_.java
rename to src/main/java/com/shenyy/dp/state/example01/thread/Thread_.java
index 41add4e..a9cfd19 100644
--- a/src/main/java/com/mashibing/dp/state/thread/Thread_.java
+++ b/src/main/java/com/shenyy/dp/state/example01/thread/Thread_.java
@@ -1,4 +1,4 @@
-package com.mashibing.dp.state.thread;
+package com.shenyy.dp.state.example01.thread;
public class Thread_ {
ThreadState_ state;
diff --git a/src/main/java/com/mashibing/dp/state/v1/MM.java b/src/main/java/com/shenyy/dp/state/example01/v1/MM.java
similarity index 88%
rename from src/main/java/com/mashibing/dp/state/v1/MM.java
rename to src/main/java/com/shenyy/dp/state/example01/v1/MM.java
index b83ec7b..0ed5224 100644
--- a/src/main/java/com/mashibing/dp/state/v1/MM.java
+++ b/src/main/java/com/shenyy/dp/state/example01/v1/MM.java
@@ -1,4 +1,4 @@
-package com.mashibing.dp.state.v1;
+package com.shenyy.dp.state.example01.v1;
/**
* 当增加新的状态时非常不方便
diff --git a/src/main/java/com/mashibing/dp/state/v2/MM.java b/src/main/java/com/shenyy/dp/state/example01/v2/MM.java
similarity index 87%
rename from src/main/java/com/mashibing/dp/state/v2/MM.java
rename to src/main/java/com/shenyy/dp/state/example01/v2/MM.java
index 8407e42..bae12d3 100644
--- a/src/main/java/com/mashibing/dp/state/v2/MM.java
+++ b/src/main/java/com/shenyy/dp/state/example01/v2/MM.java
@@ -1,4 +1,4 @@
-package com.mashibing.dp.state.v2;
+package com.shenyy.dp.state.example01.v2;
/**
* 当增加新的状态时非常不方便
diff --git a/src/main/java/com/mashibing/dp/state/v2/MMHappyState.java b/src/main/java/com/shenyy/dp/state/example01/v2/MMHappyState.java
similarity index 83%
rename from src/main/java/com/mashibing/dp/state/v2/MMHappyState.java
rename to src/main/java/com/shenyy/dp/state/example01/v2/MMHappyState.java
index 85fa36c..37159a0 100644
--- a/src/main/java/com/mashibing/dp/state/v2/MMHappyState.java
+++ b/src/main/java/com/shenyy/dp/state/example01/v2/MMHappyState.java
@@ -1,4 +1,4 @@
-package com.mashibing.dp.state.v2;
+package com.shenyy.dp.state.example01.v2;
public class MMHappyState extends MMState {
@Override
diff --git a/src/main/java/com/mashibing/dp/state/v2/MMNervousState.java b/src/main/java/com/shenyy/dp/state/example01/v2/MMNervousState.java
similarity index 79%
rename from src/main/java/com/mashibing/dp/state/v2/MMNervousState.java
rename to src/main/java/com/shenyy/dp/state/example01/v2/MMNervousState.java
index e6c28cb..70fb389 100644
--- a/src/main/java/com/mashibing/dp/state/v2/MMNervousState.java
+++ b/src/main/java/com/shenyy/dp/state/example01/v2/MMNervousState.java
@@ -1,4 +1,4 @@
-package com.mashibing.dp.state.v2;
+package com.shenyy.dp.state.example01.v2;
public class MMNervousState extends MMState {
@Override
diff --git a/src/main/java/com/mashibing/dp/state/v2/MMSadState.java b/src/main/java/com/shenyy/dp/state/example01/v2/MMSadState.java
similarity index 79%
rename from src/main/java/com/mashibing/dp/state/v2/MMSadState.java
rename to src/main/java/com/shenyy/dp/state/example01/v2/MMSadState.java
index 89fba63..e5c870b 100644
--- a/src/main/java/com/mashibing/dp/state/v2/MMSadState.java
+++ b/src/main/java/com/shenyy/dp/state/example01/v2/MMSadState.java
@@ -1,4 +1,4 @@
-package com.mashibing.dp.state.v2;
+package com.shenyy.dp.state.example01.v2;
public class MMSadState extends MMState {
@Override
diff --git a/src/main/java/com/mashibing/dp/state/v2/MMState.java b/src/main/java/com/shenyy/dp/state/example01/v2/MMState.java
similarity index 72%
rename from src/main/java/com/mashibing/dp/state/v2/MMState.java
rename to src/main/java/com/shenyy/dp/state/example01/v2/MMState.java
index 8c99c72..527ea56 100644
--- a/src/main/java/com/mashibing/dp/state/v2/MMState.java
+++ b/src/main/java/com/shenyy/dp/state/example01/v2/MMState.java
@@ -1,4 +1,4 @@
-package com.mashibing.dp.state.v2;
+package com.shenyy.dp.state.example01.v2;
public abstract class MMState {
abstract void smile();
diff --git a/src/main/java/com/shenyy/dp/strategy/Description.md b/src/main/java/com/shenyy/dp/strategy/Description.md
new file mode 100644
index 0000000..25f8f76
--- /dev/null
+++ b/src/main/java/com/shenyy/dp/strategy/Description.md
@@ -0,0 +1,33 @@
+##Description
+###Definition:
+
+Wikipedia defines strategy pattern as:
+
+“In computer programming, the strategy pattern (also known as the policy pattern) is a software design pattern that enables an algorithm’s behavior to be selected at runtime. The strategy pattern
+
+* defines a family of algorithms,
+* encapsulates each algorithm, and
+* makes the algorithms interchangeable within that family.
+
+The strategy design pattern is a behavioral pattern that allows you to change the behavior of an algorithm at runtime by switching between different strategies. In Java, the strategy design pattern can be implemented by defining an interface for the algorithm, and having multiple concrete implementations of the algorithm.
+
+
+
+Here we rely on composition instead of inheritance for reuse. Context is composed of a Strategy. Instead of implementing a behavior the Context delegates it to Strategy. The context would be the class that would require changing behaviors. We can change behavior dynamically. Strategy is implemented as interface so that we can change behavior without affecting our context.
+
+We will have a clearer understanding of strategy pattern when we will use it to solve our problem.
+
+###Advantages:
+
+1. A family of algorithms can be defined as a class hierarchy and can be used interchangeably to alter application behavior without changing its architecture.
+2. By encapsulating the algorithm separately, new algorithms complying with the same interface can be easily introduced.
+3. The application can switch strategies at run-time.
+4. Strategy enables the clients to choose the required algorithm, without using a “switch” statement or a series of “if-else” statements.
+5. Data structures used for implementing the algorithm are completely encapsulated in Strategy classes. Therefore, the implementation of an algorithm can be changed without affecting the Context class.
+
+###Disadvantages:
+
+1. The application must be aware of all the strategies to select the right one for the right situation.
+2. Context and the Strategy classes normally communicate through the interface specified by the abstract Strategy base class. Strategy base class must expose interface for all the required behaviours, which some concrete Strategy classes might not implement.
+3. In most cases, the application configures the Context with the required Strategy object. Therefore, the application needs to create and maintain two objects in place of one.
+
diff --git a/src/main/java/com/shenyy/dp/strategy/assets/classss.jpg b/src/main/java/com/shenyy/dp/strategy/assets/classss.jpg
new file mode 100644
index 0000000..1087125
Binary files /dev/null and b/src/main/java/com/shenyy/dp/strategy/assets/classss.jpg differ
diff --git a/src/main/java/com/shenyy/dp/strategy/chatgpt/CreditCardStrategy.java b/src/main/java/com/shenyy/dp/strategy/chatgpt/CreditCardStrategy.java
new file mode 100644
index 0000000..1581ea1
--- /dev/null
+++ b/src/main/java/com/shenyy/dp/strategy/chatgpt/CreditCardStrategy.java
@@ -0,0 +1,20 @@
+package com.shenyy.dp.strategy.chatgpt;
+
+public class CreditCardStrategy implements PaymentStrategy {
+ private String name;
+ private String cardNumber;
+ private String cvv;
+ private String dateOfExpiry;
+
+ public CreditCardStrategy(String name, String cardNumber, String cvv, String dateOfExpiry) {
+ this.name = name;
+ this.cardNumber = cardNumber;
+ this.cvv = cvv;
+ this.dateOfExpiry = dateOfExpiry;
+ }
+
+ @Override
+ public void pay(int amount) {
+ System.out.println(amount + " paid by credit card");
+ }
+}
diff --git a/src/main/java/com/shenyy/dp/strategy/chatgpt/PayPalStrategy.java b/src/main/java/com/shenyy/dp/strategy/chatgpt/PayPalStrategy.java
new file mode 100644
index 0000000..528436a
--- /dev/null
+++ b/src/main/java/com/shenyy/dp/strategy/chatgpt/PayPalStrategy.java
@@ -0,0 +1,16 @@
+package com.shenyy.dp.strategy.chatgpt;
+
+public class PayPalStrategy implements PaymentStrategy{
+ private String emailId;
+ private String password;
+
+ public PayPalStrategy(String emailId, String password) {
+ this.emailId = emailId;
+ this.password = password;
+ }
+
+ @Override
+ public void pay(int amount) {
+ System.out.println(amount + " paid by PayPal.");
+ }
+}
diff --git a/src/main/java/com/shenyy/dp/strategy/chatgpt/PaymentStrategy.java b/src/main/java/com/shenyy/dp/strategy/chatgpt/PaymentStrategy.java
new file mode 100644
index 0000000..e1af6ee
--- /dev/null
+++ b/src/main/java/com/shenyy/dp/strategy/chatgpt/PaymentStrategy.java
@@ -0,0 +1,5 @@
+package com.shenyy.dp.strategy.chatgpt;
+
+public interface PaymentStrategy {
+ void pay(int amount);
+}
diff --git a/src/main/java/com/shenyy/dp/strategy/chatgpt/ShoppingCart.java b/src/main/java/com/shenyy/dp/strategy/chatgpt/ShoppingCart.java
new file mode 100644
index 0000000..46e497c
--- /dev/null
+++ b/src/main/java/com/shenyy/dp/strategy/chatgpt/ShoppingCart.java
@@ -0,0 +1,13 @@
+package com.shenyy.dp.strategy.chatgpt;
+
+public class ShoppingCart {
+ private int amount;
+
+ public ShoppingCart(int amount) {
+ this.amount = amount;
+ }
+
+ public void pay(PaymentStrategy paymentStrategy) {
+ paymentStrategy.pay(amount);
+ }
+}
diff --git a/src/main/java/com/shenyy/dp/strategy/chatgpt/StrategyExample.java b/src/main/java/com/shenyy/dp/strategy/chatgpt/StrategyExample.java
new file mode 100644
index 0000000..6f2feed
--- /dev/null
+++ b/src/main/java/com/shenyy/dp/strategy/chatgpt/StrategyExample.java
@@ -0,0 +1,9 @@
+package com.shenyy.dp.strategy.chatgpt;
+
+public class StrategyExample {
+ public static void main(String[] args) {
+ ShoppingCart shoppingCart = new ShoppingCart(99);
+ shoppingCart.pay(new CreditCardStrategy("Pankaj Kumar", "1234567890123456", "786", "12/15"));
+ shoppingCart.pay(new PayPalStrategy("myemail@example.com", "mypwd"));
+ }
+}
diff --git a/src/main/java/com/mashibing/dp/strategy/Cat.java b/src/main/java/com/shenyy/dp/strategy/example01/Cat.java
similarity index 92%
rename from src/main/java/com/mashibing/dp/strategy/Cat.java
rename to src/main/java/com/shenyy/dp/strategy/example01/Cat.java
index 1d2d7cd..f33beba 100644
--- a/src/main/java/com/mashibing/dp/strategy/Cat.java
+++ b/src/main/java/com/shenyy/dp/strategy/example01/Cat.java
@@ -1,4 +1,4 @@
-package com.mashibing.dp.strategy;
+package com.shenyy.dp.strategy.example01;
public class Cat implements Comparable {
int weight, height;
diff --git a/src/main/java/com/mashibing/dp/strategy/CatHeightComparator.java b/src/main/java/com/shenyy/dp/strategy/example01/CatHeightComparator.java
similarity index 85%
rename from src/main/java/com/mashibing/dp/strategy/CatHeightComparator.java
rename to src/main/java/com/shenyy/dp/strategy/example01/CatHeightComparator.java
index ae30fda..373d235 100644
--- a/src/main/java/com/mashibing/dp/strategy/CatHeightComparator.java
+++ b/src/main/java/com/shenyy/dp/strategy/example01/CatHeightComparator.java
@@ -1,4 +1,4 @@
-package com.mashibing.dp.strategy;
+package com.shenyy.dp.strategy.example01;
public class CatHeightComparator implements Comparator {
@Override
diff --git a/src/main/java/com/mashibing/dp/strategy/CatWeightComparator.java b/src/main/java/com/shenyy/dp/strategy/example01/CatWeightComparator.java
similarity index 85%
rename from src/main/java/com/mashibing/dp/strategy/CatWeightComparator.java
rename to src/main/java/com/shenyy/dp/strategy/example01/CatWeightComparator.java
index 7969a02..90354d2 100644
--- a/src/main/java/com/mashibing/dp/strategy/CatWeightComparator.java
+++ b/src/main/java/com/shenyy/dp/strategy/example01/CatWeightComparator.java
@@ -1,4 +1,4 @@
-package com.mashibing.dp.strategy;
+package com.shenyy.dp.strategy.example01;
public class CatWeightComparator implements Comparator {
@Override
diff --git a/src/main/java/com/mashibing/dp/strategy/Comparable.java b/src/main/java/com/shenyy/dp/strategy/example01/Comparable.java
similarity index 58%
rename from src/main/java/com/mashibing/dp/strategy/Comparable.java
rename to src/main/java/com/shenyy/dp/strategy/example01/Comparable.java
index ef031ea..5025c95 100644
--- a/src/main/java/com/mashibing/dp/strategy/Comparable.java
+++ b/src/main/java/com/shenyy/dp/strategy/example01/Comparable.java
@@ -1,4 +1,4 @@
-package com.mashibing.dp.strategy;
+package com.shenyy.dp.strategy.example01;
public interface Comparable {
int compareTo(T o);
diff --git a/src/main/java/com/mashibing/dp/strategy/Comparator.java b/src/main/java/com/shenyy/dp/strategy/example01/Comparator.java
similarity index 78%
rename from src/main/java/com/mashibing/dp/strategy/Comparator.java
rename to src/main/java/com/shenyy/dp/strategy/example01/Comparator.java
index 093667d..dda7962 100644
--- a/src/main/java/com/mashibing/dp/strategy/Comparator.java
+++ b/src/main/java/com/shenyy/dp/strategy/example01/Comparator.java
@@ -1,4 +1,4 @@
-package com.mashibing.dp.strategy;
+package com.shenyy.dp.strategy.example01;
@FunctionalInterface
public interface Comparator {
diff --git a/src/main/java/com/mashibing/dp/strategy/Dog.java b/src/main/java/com/shenyy/dp/strategy/example01/Dog.java
similarity index 90%
rename from src/main/java/com/mashibing/dp/strategy/Dog.java
rename to src/main/java/com/shenyy/dp/strategy/example01/Dog.java
index 9584a37..a1dcc92 100644
--- a/src/main/java/com/mashibing/dp/strategy/Dog.java
+++ b/src/main/java/com/shenyy/dp/strategy/example01/Dog.java
@@ -1,4 +1,4 @@
-package com.mashibing.dp.strategy;
+package com.shenyy.dp.strategy.example01;
public class Dog implements Comparable {
diff --git a/src/main/java/com/mashibing/dp/strategy/DogComparator.java b/src/main/java/com/shenyy/dp/strategy/example01/DogComparator.java
similarity index 84%
rename from src/main/java/com/mashibing/dp/strategy/DogComparator.java
rename to src/main/java/com/shenyy/dp/strategy/example01/DogComparator.java
index c90d859..53e8e97 100644
--- a/src/main/java/com/mashibing/dp/strategy/DogComparator.java
+++ b/src/main/java/com/shenyy/dp/strategy/example01/DogComparator.java
@@ -1,4 +1,4 @@
-package com.mashibing.dp.strategy;
+package com.shenyy.dp.strategy.example01;
public class DogComparator implements Comparator {
@Override
diff --git a/src/main/java/com/mashibing/dp/strategy/Main.java b/src/main/java/com/shenyy/dp/strategy/example01/Main.java
similarity index 93%
rename from src/main/java/com/mashibing/dp/strategy/Main.java
rename to src/main/java/com/shenyy/dp/strategy/example01/Main.java
index a723f20..ffd6f19 100644
--- a/src/main/java/com/mashibing/dp/strategy/Main.java
+++ b/src/main/java/com/shenyy/dp/strategy/example01/Main.java
@@ -1,4 +1,4 @@
-package com.mashibing.dp.strategy;
+package com.shenyy.dp.strategy.example01;
import java.util.Arrays;
diff --git a/src/main/java/com/mashibing/dp/strategy/Sorter.java b/src/main/java/com/shenyy/dp/strategy/example01/Sorter.java
similarity index 92%
rename from src/main/java/com/mashibing/dp/strategy/Sorter.java
rename to src/main/java/com/shenyy/dp/strategy/example01/Sorter.java
index a2c42fb..e58147d 100644
--- a/src/main/java/com/mashibing/dp/strategy/Sorter.java
+++ b/src/main/java/com/shenyy/dp/strategy/example01/Sorter.java
@@ -1,4 +1,4 @@
-package com.mashibing.dp.strategy;
+package com.shenyy.dp.strategy.example01;
public class Sorter {
diff --git a/src/main/java/com/shenyy/dp/templatemethod/Description.md b/src/main/java/com/shenyy/dp/templatemethod/Description.md
new file mode 100644
index 0000000..18b22f8
--- /dev/null
+++ b/src/main/java/com/shenyy/dp/templatemethod/Description.md
@@ -0,0 +1,28 @@
+##Description
+The Template method is a Behavioral Design Pattern that defines the skeleton of the operation and leaves the details to be implemented by the child class. Its subclasses can override the method implementations as per need but the invocation is to be in the same way as defined by an abstract class. It is one of the easiest among the Behavioral design pattern to understand and implements. Such methods are highly used in framework development as they allow us to reuse the single piece of code at different places by making certain changes. This leads to avoiding code duplication also.
+
+###Problem without using Template Method
+Imagine you are working on a **Chatbot application** as a software developer which uses data mining techniques to analyze the data of the corporate documents. Initially, your applications were fine with the pdf version of the data only but later your applications also require to collect and convert data from other formats also such as **XML, CSV,** and others. After implementing the whole scenario for the other formats also, you noticed that all the classes have lots of similar code. Part of the code like analyzing and processing was identical in almost all classes whereas they differ in dealing with the data.
+
+###Solution using Template Method
+Let’s discuss the solution to the above-described problem using the template method. It suggests to break down the code into a series of steps and convert these steps into methods and put series call inside the template_function. Hence we created the **templateFunction** separately and create methods such as **getXml, getPdf and getCsv** for dealing with the code separately
+
+###UML Diagram
+
+* **AbstractClass** contains the templateMethod() which should be made final so that it cannot be overridden. This template method makes use of other operations available in order to run the algorithm but is decoupled for the actual implementation of these methods. All operations used by this template method are made abstract, so their implementation is deferred to subclasses.
+* **ConcreteClass** implements all the operations required by the templateMethod that were defined as abstract in the parent class. There can be many different ConcreteClasses.
+
+###Advantages
+* Equivalent Content: It’s easy to consider the duplicate code in the superclass by pulling it there where you want to use it.
+* Flexibility: It provides vast flexibility such that subclasses are able to decide how to implement the steps of the algorithms.
+* Possibility of Inheritance: We can reuse our code as the Template Method uses inheritance which provides the ability of code reusability.
+
+###Disadvantages
+* Complex Code: The code may become enough complex sometimes while using the template method such that it becomes too much hard to understand the code even by the developers who are writing it.
+* Limitness: Clients may ask for the extended version because sometimes they feel lack of algorithms in the provided skeleton.
+* Violation: It might be possible that by using Template method, you may end up with violating the Liskov Substitution Principle which is definitely not the good thing to follow.
+
+###Applicability
+* Extension by Clients: This method is always preferred to use when you want to let clients extend the algorithm using particular steps but with not the whole structure of the algorithm.
+* Similar Algorithms: When you have a lot of similar algorithms with minor changes, its always better to use the template design pattern because if some changes occur in the algorithm, then you don’t have to make changes in each algorithm.
+* Development of Frameworks: It is highly recommended to use the template design pattern while developing a framework because it will help us to avoid the duplicate code as well as reusing the piece of code again and again by making certain changes.
diff --git a/src/main/java/com/shenyy/dp/templatemethod/assets/Problem-Template-Method.png b/src/main/java/com/shenyy/dp/templatemethod/assets/Problem-Template-Method.png
new file mode 100644
index 0000000..c21cb83
Binary files /dev/null and b/src/main/java/com/shenyy/dp/templatemethod/assets/Problem-Template-Method.png differ
diff --git a/src/main/java/com/shenyy/dp/templatemethod/assets/claasDia.jpg b/src/main/java/com/shenyy/dp/templatemethod/assets/claasDia.jpg
new file mode 100644
index 0000000..9cb8224
Binary files /dev/null and b/src/main/java/com/shenyy/dp/templatemethod/assets/claasDia.jpg differ
diff --git a/src/main/java/com/shenyy/dp/templatemethod/chatgpt/Cricket.java b/src/main/java/com/shenyy/dp/templatemethod/chatgpt/Cricket.java
new file mode 100644
index 0000000..cef91c1
--- /dev/null
+++ b/src/main/java/com/shenyy/dp/templatemethod/chatgpt/Cricket.java
@@ -0,0 +1,20 @@
+package com.shenyy.dp.templatemethod.chatgpt;
+
+public class Cricket extends Game {
+ private String name = "Cricket game";
+
+ @Override
+ void initialize() {
+ System.out.println(name + " initialize");
+ }
+
+ @Override
+ void startPlay() {
+ System.out.println(name + " start");
+ }
+
+ @Override
+ void endPlay() {
+ System.out.println(name + " end");
+ }
+}
diff --git a/src/main/java/com/shenyy/dp/templatemethod/chatgpt/Football.java b/src/main/java/com/shenyy/dp/templatemethod/chatgpt/Football.java
new file mode 100644
index 0000000..4f04062
--- /dev/null
+++ b/src/main/java/com/shenyy/dp/templatemethod/chatgpt/Football.java
@@ -0,0 +1,20 @@
+package com.shenyy.dp.templatemethod.chatgpt;
+
+public class Football extends Game{
+ private String name = "Football game";
+
+ @Override
+ void initialize() {
+ System.out.println(name + " initialize");
+ }
+
+ @Override
+ void startPlay() {
+ System.out.println(name + " start");
+ }
+
+ @Override
+ void endPlay() {
+ System.out.println(name + " end");
+ }
+}
diff --git a/src/main/java/com/shenyy/dp/templatemethod/chatgpt/Game.java b/src/main/java/com/shenyy/dp/templatemethod/chatgpt/Game.java
new file mode 100644
index 0000000..23a3f3e
--- /dev/null
+++ b/src/main/java/com/shenyy/dp/templatemethod/chatgpt/Game.java
@@ -0,0 +1,15 @@
+package com.shenyy.dp.templatemethod.chatgpt;
+
+abstract class Game {
+ abstract void initialize();
+
+ abstract void startPlay();
+
+ abstract void endPlay();
+
+ public void play() {
+ initialize();
+ startPlay();
+ endPlay();
+ }
+}
diff --git a/src/main/java/com/shenyy/dp/templatemethod/chatgpt/TemplateMethodExample.java b/src/main/java/com/shenyy/dp/templatemethod/chatgpt/TemplateMethodExample.java
new file mode 100644
index 0000000..91c6e85
--- /dev/null
+++ b/src/main/java/com/shenyy/dp/templatemethod/chatgpt/TemplateMethodExample.java
@@ -0,0 +1,11 @@
+package com.shenyy.dp.templatemethod.chatgpt;
+
+public class TemplateMethodExample {
+ public static void main(String[] args) {
+ Game game = new Cricket();
+ game.play();
+ System.out.println();
+ game = new Football();
+ game.play();
+ }
+}
diff --git a/src/main/java/com/mashibing/dp/TemplateMethod/Main.java b/src/main/java/com/shenyy/dp/templatemethod/example01/Main.java
similarity index 89%
rename from src/main/java/com/mashibing/dp/TemplateMethod/Main.java
rename to src/main/java/com/shenyy/dp/templatemethod/example01/Main.java
index 4a3a847..51a6e0c 100644
--- a/src/main/java/com/mashibing/dp/TemplateMethod/Main.java
+++ b/src/main/java/com/shenyy/dp/templatemethod/example01/Main.java
@@ -1,4 +1,4 @@
-package com.mashibing.dp.TemplateMethod;
+package com.shenyy.dp.templatemethod.example01;
public class Main {
public static void main(String[] args) {
diff --git a/src/main/java/com/shenyy/dp/visitor/Description.md b/src/main/java/com/shenyy/dp/visitor/Description.md
new file mode 100644
index 0000000..f0a339f
--- /dev/null
+++ b/src/main/java/com/shenyy/dp/visitor/Description.md
@@ -0,0 +1,27 @@
+##Description
+Visitor design pattern is one of the behavioral design patterns. It is used when we have to perform an operation on a group of similar kind of Objects. With the help of visitor pattern, we can move the operational logic from the objects to another class.
+
+The visitor pattern consists of two parts:
+
+* a method called **Visit()** which is implemented by the visitor and is called for every element in the data structure
+* visitable classes providing **Accept()** methods that accept a visitor
+
+
+
+###
Design components
+
+* **Client** : The Client class is a consumer of the classes of the visitor design pattern. It has access to the data structure objects and can instruct them to accept a Visitor to perform the appropriate processing.
+* **Visitor** : This is an interface or an abstract class used to declare the visit operations for all the types of visitable classes.
+* **ConcreteVisitor** : For each type of visitor all the visit methods, declared in abstract visitor, must be implemented. Each Visitor will be responsible for different operations.
+* **Visitable** : This is an interface which declares the accept operation. This is the entry point which enables an object to be “visited” by the visitor object.
+* **ConcreteVisitable** : These classes implement the Visitable interface or class and defines the accept operation. The visitor object is passed to this object using the accept operation.
+
+Here, in the implementation if accept() method in all the items are same but it can be different. For example there can be logic to check if item is free then don’t call the visit() method at all.
+
+###Advantages :
+* If the logic of operation changes, then we need to make change only in the visitor implementation rather than doing it in all the item classes.
+* Adding a new item to the system is easy, it will require change only in visitor interface and implementation and existing item classes will not be affected.
+
+###Disadvantages :
+* We should know the return type of visit() methods at the time of designing otherwise we will have to change the interface and all of its implementations.
+* If there are too many implementations of visitor interface, it makes it hard to extend.
diff --git a/src/main/java/com/shenyy/dp/visitor/assets/Visitor-Design-Pattern-Diagram.png b/src/main/java/com/shenyy/dp/visitor/assets/Visitor-Design-Pattern-Diagram.png
new file mode 100644
index 0000000..c3f60cd
Binary files /dev/null and b/src/main/java/com/shenyy/dp/visitor/assets/Visitor-Design-Pattern-Diagram.png differ
diff --git a/src/main/java/com/shenyy/dp/visitor/chatgpt/ConcreteElementA.java b/src/main/java/com/shenyy/dp/visitor/chatgpt/ConcreteElementA.java
new file mode 100644
index 0000000..ae80885
--- /dev/null
+++ b/src/main/java/com/shenyy/dp/visitor/chatgpt/ConcreteElementA.java
@@ -0,0 +1,8 @@
+package com.shenyy.dp.visitor.chatgpt;
+
+public class ConcreteElementA implements Element {
+ @Override
+ public void accept(Visitor visitor) {
+ visitor.visit(this);
+ }
+}
diff --git a/src/main/java/com/shenyy/dp/visitor/chatgpt/ConcreteElementB.java b/src/main/java/com/shenyy/dp/visitor/chatgpt/ConcreteElementB.java
new file mode 100644
index 0000000..b868ce0
--- /dev/null
+++ b/src/main/java/com/shenyy/dp/visitor/chatgpt/ConcreteElementB.java
@@ -0,0 +1,8 @@
+package com.shenyy.dp.visitor.chatgpt;
+
+public class ConcreteElementB implements Element{
+ @Override
+ public void accept(Visitor visitor) {
+ visitor.visit(this);
+ }
+}
diff --git a/src/main/java/com/shenyy/dp/visitor/chatgpt/ConcreteVisitor.java b/src/main/java/com/shenyy/dp/visitor/chatgpt/ConcreteVisitor.java
new file mode 100644
index 0000000..22085d9
--- /dev/null
+++ b/src/main/java/com/shenyy/dp/visitor/chatgpt/ConcreteVisitor.java
@@ -0,0 +1,13 @@
+package com.shenyy.dp.visitor.chatgpt;
+
+public class ConcreteVisitor implements Visitor{
+ @Override
+ public void visit(ConcreteElementA concreteElementA) {
+ System.out.println("Visiting ConcreteElementA");
+ }
+
+ @Override
+ public void visit(ConcreteElementB concreteElementB) {
+ System.out.println("Visiting ConcreteElementB");
+ }
+}
diff --git a/src/main/java/com/shenyy/dp/visitor/chatgpt/Element.java b/src/main/java/com/shenyy/dp/visitor/chatgpt/Element.java
new file mode 100644
index 0000000..39f414c
--- /dev/null
+++ b/src/main/java/com/shenyy/dp/visitor/chatgpt/Element.java
@@ -0,0 +1,5 @@
+package com.shenyy.dp.visitor.chatgpt;
+
+public interface Element {
+ void accept(Visitor visitor);
+}
diff --git a/src/main/java/com/shenyy/dp/visitor/chatgpt/Visitor.java b/src/main/java/com/shenyy/dp/visitor/chatgpt/Visitor.java
new file mode 100644
index 0000000..d56ade2
--- /dev/null
+++ b/src/main/java/com/shenyy/dp/visitor/chatgpt/Visitor.java
@@ -0,0 +1,7 @@
+package com.shenyy.dp.visitor.chatgpt;
+
+public interface Visitor {
+ void visit(ConcreteElementA concreteElementA);
+
+ void visit(ConcreteElementB concreteElementB);
+}
diff --git a/src/main/java/com/shenyy/dp/visitor/chatgpt/VisitorExample.java b/src/main/java/com/shenyy/dp/visitor/chatgpt/VisitorExample.java
new file mode 100644
index 0000000..1c8e83b
--- /dev/null
+++ b/src/main/java/com/shenyy/dp/visitor/chatgpt/VisitorExample.java
@@ -0,0 +1,17 @@
+package com.shenyy.dp.visitor.chatgpt;
+
+import java.util.ArrayList;
+import java.util.List;
+
+public class VisitorExample {
+ public static void main(String[] args) {
+ List elements = new ArrayList<>();
+ elements.add(new ConcreteElementA());
+ elements.add(new ConcreteElementB());
+
+ Visitor visitor = new ConcreteVisitor();
+ for (Element element : elements) {
+ element.accept(visitor);
+ }
+ }
+}
diff --git a/src/main/java/com/mashibing/dp/visitor/Computer.java b/src/main/java/com/shenyy/dp/visitor/example01/Computer.java
similarity index 98%
rename from src/main/java/com/mashibing/dp/visitor/Computer.java
rename to src/main/java/com/shenyy/dp/visitor/example01/Computer.java
index dfaa618..969641f 100644
--- a/src/main/java/com/mashibing/dp/visitor/Computer.java
+++ b/src/main/java/com/shenyy/dp/visitor/example01/Computer.java
@@ -1,4 +1,4 @@
-package com.mashibing.dp.visitor;
+package com.shenyy.dp.visitor.example01;
public class Computer {
ComputerPart cpu = new CPU();
diff --git "a/src/main/java/com/shenyy/introduction/1.1\344\273\200\344\271\210\346\230\257\350\256\276\350\256\241\346\250\241\345\274\217.md" "b/src/main/java/com/shenyy/introduction/1.1\344\273\200\344\271\210\346\230\257\350\256\276\350\256\241\346\250\241\345\274\217.md"
new file mode 100644
index 0000000..06357ed
--- /dev/null
+++ "b/src/main/java/com/shenyy/introduction/1.1\344\273\200\344\271\210\346\230\257\350\256\276\350\256\241\346\250\241\345\274\217.md"
@@ -0,0 +1,15 @@
+## 什么是设计模式
+
+设计模式使人们可以更加简单方便地复用成功的设计和体系结构。
+
+将已证实的技术表述成设计模式也会使新系统开发者更加容易理解其设计思路。
+
+### 基本要素
+
+一般而言,一个模式有四个基本要素:
+1. **模式名称**(pattern name) 一个助记名,它用一两个词来描述模式的问题、解决方案和效果。
+2. **问题**(problem) 描述了应该在何时使用模式。
+3. **解决方案**(solution) 描述了设计的组成成分,它们之间的相互关系及各自的职责和协作方式。
+4. **效果**(consequences) 描述了模式应用的效果及使用模式应权衡的问题。
+
+设计模式是对被用来在特定场景下解决一般设计问题的类和相互通信的对象的描述。
\ No newline at end of file
diff --git "a/src/main/java/com/shenyy/introduction/1.2MVC\344\270\255\347\232\204\350\256\276\350\256\241\346\250\241\345\274\217.md" "b/src/main/java/com/shenyy/introduction/1.2MVC\344\270\255\347\232\204\350\256\276\350\256\241\346\250\241\345\274\217.md"
new file mode 100644
index 0000000..a78da2a
--- /dev/null
+++ "b/src/main/java/com/shenyy/introduction/1.2MVC\344\270\255\347\232\204\350\256\276\350\256\241\346\250\241\345\274\217.md"
@@ -0,0 +1,106 @@
+## MVC 中的设计模式
+
+MVC 的模型/视图/控制器(Model / View / Controller)三元组被用来构建用户界面。
+
+### MVC 介绍
+
+MVC包括三类对象:
+
+- 模型 Model 是应用对象
+- 视图 View 是它在屏幕上的表示
+- 控制器 Controller 定义用户界面对用户输入的响应方式
+
+不使用 MVC,用户界面设计往往将这些对象混在一起,而 MVC 则将它们分离以提高灵活性和复用性。
+
+### MVC 中的设计模式
+
+MVC 的主要关系还是由 Observer、Composite和
+Strategy 三个设计模式给出的。
+
+MVC 还使用了其他的设计模式,如:用来指定视图缺省控制器的 FactoryMethod 和用来增加视图滚动的Decorator。
+
+### 视图和模型的关系
+
+MVC 通过建立一个 “订购/通知” 协议来分离视图和模型。
+
+视图必须保证它的显示正确地反映了模型的状态。
+
+一旦模型的数据发生变化,模型将通知有关的视图,每个视图相应地得到刷新自己的机会。
+
+这种方法可以让你为一个模型提供不同的多个视图表现形式,也能够为一个模型创建新的视图而无须重写模型。
+
+#### 示例
+
+模型包含一些数据值,视图通过电子表格、柱状图、饼图这些不同的方式来显示这些数据。
+
+当模型的数据发生变化时,模型就通知它的视图,而视图将与模型通信以访问这些数据值。
+
+
+
+#### Observer 模式
+
+表面上看,这个例子反映了将视图和模型分离的设计,然而这个设计还可用于解决更一
+般的问题:
+
+将对象分离,使得一个对象的改变能够影响另一些对象,而这个对象并不需要知
+道那些被影响的对象的细节。
+
+这个更一般的设计被描述成 **Observer 模式**。
+
+### 嵌套视图
+
+MVC 的另一个特征是视图可以嵌套。
+
+#### 示例
+
+按钮控制面板可以用一个嵌套了按钮的复杂
+视图来实现。
+
+对象查看器的用户界面可由嵌套的视图构成,这些视图又可复用于调试器。
+
+MVC 用 View 类的子类 — `CompositeView` 类来支持嵌套视图。
+
+`CompositeView`类的对象行为上类似于 View 类对象,一个组合视图可用于任何视图可用的地方,但是它包含并管理嵌套视图。
+
+#### Composite 模式
+
+上例反映了可以将组合视图与其构件平等对待的设计,同样地,该设计也适用于更一般
+的问题:
+
+将一些对象划为一组,并将该组对象当作一个对象来使用。
+
+这个设计被描述为
+**Composite 模式**。
+
+Composite 模式允许你创建一个类层次结构,一些子类定义了原子对象(如
+Button)而其他类定义了组合对象(CompositeView),这些组合对象是由原子对象组合而成的更复杂的对象。
+
+### 视图和控制器
+
+MVC 允许你在不改变视图外观的情况下改变视图对用户输入的响应方式。
+
+#### 示例
+
+你可能希望改变视图对键盘的响应方式,或希望使用弹出菜单而不是原来的命令键方式。
+
+MVC 将响应机制封装在 Controller 对象中。
+
+存在着一个 Controller 的类层次结构,使得可以方便地对原有
+Controller 做适当改变而创建新的 Controller。
+
+View 使用 Controller 子类的实例来实现一个特定的响应策略。
+
+要实现不同的响应策略只要用不同种类的 Controller 实例替换即可。
+
+甚至可以在运行时刻通过改变 View 的 Controller 来改变
+View 对用户输入的响应方式。
+
+例如,一个View可以被禁止接收任何输入,只需给它一个忽略
+输入事件的Controller。
+
+#### Strategy 模式
+
+View-Controller 关系是 Strategy 模式的一个例子。一个策略是一个表述算法的对象。
+
+当你想静态或动态地替换一个算法,或你有很多不同的算法,或算法中包含你想封装的复杂
+数据结构,这时策略模式是非常有用的。
\ No newline at end of file
diff --git "a/src/main/java/com/shenyy/introduction/1.3\346\217\217\350\277\260\350\256\276\350\256\241\346\250\241\345\274\217.md" "b/src/main/java/com/shenyy/introduction/1.3\346\217\217\350\277\260\350\256\276\350\256\241\346\250\241\345\274\217.md"
new file mode 100644
index 0000000..845d7e2
--- /dev/null
+++ "b/src/main/java/com/shenyy/introduction/1.3\346\217\217\350\277\260\350\256\276\350\256\241\346\250\241\345\274\217.md"
@@ -0,0 +1,36 @@
+## 描述设计模式
+
+为了达到设计复用,我们必须同时记录设计产生的决定过程、选择过程和权衡过程。
+
+我们将用统一的格式描述设计模式,每一个模式根据以下的模板被分成若干部分:
+
+- **模式名和分类**
+ 模式名简洁地描述了模式的本质。
+- **意图**
+ 是回答下列问题的简单陈述:设计模式是做什么的?它的基本原理和意图是什么?它解决的是什么样的特定设计问题?
+- **别名**
+ 模式的其他名称。
+- **动机**
+ 用以说明一个设计问题以及如何用模式中的类、对象来解决该问题的特定情景。
+- **适用性**
+ 什么情况下可以使用该设计模式?该模式可用来改进哪些不良设计?你怎样识别这些情况?
+- **结构**
+ 采用基于对象建模技术的表示法对模式中的类进行图形描述。
+- **参与者**
+ 指设计模式中的类和/或对象以及它们各自的职责。
+- **协作**
+ 模式的参与者怎样协作以实现它们的职责。
+- **效果**
+ 模式怎样支持它的目标?使用模式的效果和所需做的权衡取舍?系统结构的哪些方面可
+ 以独立改变?
+- **实现**
+ 实现模式时需要知道的一些提示、技术要点及应避免的缺陷,以及是否存在某些特定于
+ 实现语言的问题。
+- **代码示例**
+ 用来说明怎样用 Java 实现该模式的代码片段。
+- **已知应用**
+ 实际系统中发现的模式的例子。每个模式至少包括了两个不同领域的实例。
+- **相关模式**
+ 与这个模式紧密相关的模式有哪些?其间重要的不同之处是什么?这个模式应与哪些其
+ 他模式一起使用?
+
diff --git "a/src/main/java/com/shenyy/introduction/1.4\350\256\276\350\256\241\346\250\241\345\274\217\347\232\204\345\210\206\347\261\273.md" "b/src/main/java/com/shenyy/introduction/1.4\350\256\276\350\256\241\346\250\241\345\274\217\347\232\204\345\210\206\347\261\273.md"
new file mode 100644
index 0000000..4339a76
--- /dev/null
+++ "b/src/main/java/com/shenyy/introduction/1.4\350\256\276\350\256\241\346\250\241\345\274\217\347\232\204\345\210\206\347\261\273.md"
@@ -0,0 +1,52 @@
+## 设计模式的分类
+
+从第3章开始的模式目录中共包含 23 个设计模式。
+
+它们的名字和意图列举如下:
+
+- **AbstractFactory**(3.1):
+提供一个创建一系列相关或相互依赖对象的接口,而无需指定它们具体的类。
+- **Adapter**(4.1):
+将一个类的接口转换成客户希望的另外一个接口。Adapter模式使得原本由于接口不兼容而不能一起工作的那些类可以一起工作。
+- **Bridge**(4.2):
+将抽象部分与它的实现部分分离,使它们都可以独立地变化。
+- **Builder**(3.2):
+将一个复杂对象的构建与它的表示分离,使得同样的构建过程可以创建不同的表示。
+- **ChainofResponsibility**(5.1):
+为解除请求的发送者和接收者之间耦合,而使多个对象都有机会处理这个请求。将这些对象连成一条链,并沿着这条链传递该请求,直到有一个对象处理它。
+- **Command**(5.2):
+将一个请求封装为一个对象,从而使你可用不同的请求对客户进行参数化;对请求排队或记录请求日志,以及支持可取消的操作。
+- **Composite**(4.3):
+将对象组合成树形结构以表示“部分-整体”的层次结构。Composite使得客户对单个对象和复合对象的使用具有一致性。
+- **Decorator**(4.4):
+动态地给一个对象添加一些额外的职责。就扩展功能而言,Decorator模式比生成子类方式更为灵活。
+- **Facade**(4.5):
+为子系统中的一组接口提供一个一致的界面,Facade模式定义了一个高层接口,这个接口使得这一子系统更加容易使用。
+- **FactoryMethod**(3.3):
+定义一个用于创建对象的接口,让子类决定将哪一个类实例化。FactoryMethod使一个类的实例化延迟到其子类。
+- **Flyweight**(4.6):
+运用共享技术有效地支持大量细粒度的对象。
+- **Interpreter**(5.3):
+给定一个语言,定义它的文法的一种表示,并定义一个解释器,该解释器使用该表示来解释语言中的句子。
+- **Iterator**(5.4):
+提供一种方法顺序访问一个聚合对象中各个元素,而又不需暴露该对象的内部表示。
+- **Mediator**(5.5):
+用一个中介对象来封装一系列的对象交互。中介者使各对象不需要显式地相互引用,从而使其耦合松散,而且可以独立地改变它们之间的交互。
+- **Memento**(5.6):
+在不破坏封装性的前提下,捕获一个对象的内部状态,并在该对象之外保存这个状态。这样以后就可将该对象恢复到保存的状态。
+- **Observer**(5.7):
+定义对象间的一种一对多的依赖关系,以便当一个对象的状态发生改变时,所有依赖于它的对象都得到通知并自动刷新。
+- **Prototype**(3.4):
+用原型实例指定创建对象的种类,并且通过拷贝这个原型来创建新的对象。
+- **Proxy**(4.7):
+为其他对象提供一个代理以控制对这个对象的访问。
+- **Singleton**(3.5):
+保证一个类仅有一个实例,并提供一个访问它的全局访问点。
+- **State**(5.8):
+允许一个对象在其内部状态改变时改变它的行为。对象看起来似乎修改了它所属的类。
+- **Strategy**(5.9):
+定义一系列的算法,把它们一个个封装起来,并且使它们可相互替换。本模式使得算法的变化可独立于使用它的客户。
+- **TemplateMethod**(5.10):
+定义一个操作中的算法的骨架,而将一些步骤延迟到子类中。TemplateMethod使得子类可以不改变一个算法的结构即可重定义该算法的某些特定步骤。
+- **Visitor**(5.11):
+表示一个作用于某对象结构中的各元素的操作。它使你可以在不改变各元素的类的前提下定义作用于这些元素的新操作。
\ No newline at end of file
diff --git "a/src/main/java/com/shenyy/introduction/1.5\350\256\276\350\256\241\346\250\241\345\274\217\347\232\204\347\273\204\347\273\207\345\210\206\347\261\273.md" "b/src/main/java/com/shenyy/introduction/1.5\350\256\276\350\256\241\346\250\241\345\274\217\347\232\204\347\273\204\347\273\207\345\210\206\347\261\273.md"
new file mode 100644
index 0000000..f44ec5f
--- /dev/null
+++ "b/src/main/java/com/shenyy/introduction/1.5\350\256\276\350\256\241\346\250\241\345\274\217\347\232\204\347\273\204\347\273\207\345\210\206\347\261\273.md"
@@ -0,0 +1,38 @@
+## 设计模式的组织分类
+
+分类有助于更快地学习目录中的模式,且对发现新的模式也有指导作用:
+
+
+
+#### 分类标准之目的准则
+
+目的准则,即模式是用来完成什么工作的。
+
+模式依据其目的可分为:
+
+- **创建型** (Creational):创建型模式与对象的创建有关。
+- **结构型** (Structural):结构型模式处理类或对象的组合。
+- **行为型**
+ (Behavioral):行为型模式对类或对象怎样交互和怎样分配职责进行描述。
+
+#### 分类标准之范围准则
+
+范围准则,指定模式主要是用于类还是用于对象。
+
+- **类模式** 处理类和子类之间的关系,这些关系通过继承建立,是静态的,在编译时刻便确定下来了。
+- **对象模式** 处理对象间的关系,这些关系在运行时刻是可以变化的,更具动态性。
+
+从某种意义上来说,几乎所有模式都使用继承机制,所以“类模式”只指那些集中于处理类间关系的模式,而大部分模式都属于对象模式的范畴。
+
+#### 两种分类标准的联系
+
+- **创建型类模式** 将对象的部分创建工作延迟到子类,而 **创建型对象模式** 则将它延迟到另一
+ 个对象中。
+- **结构型类模式** 使用继承机制来组合类,而 **结构型对象模式** 则描述了对象的组装方式。
+- **行为型类模式** 使用继承描述算法和控制流,而 **行为型对象模式** 则描述一组对象怎样协作
+ 完成单个对象所无法完成的任务。
+
+#### 不同设计模式的关系
+
+
+
diff --git "a/src/main/java/com/shenyy/introduction/1.6\350\256\276\350\256\241\346\250\241\345\274\217\350\247\243\345\206\263\350\256\276\350\256\241\351\227\256\351\242\230\347\232\204\346\226\271\345\274\217.md" "b/src/main/java/com/shenyy/introduction/1.6\350\256\276\350\256\241\346\250\241\345\274\217\350\247\243\345\206\263\350\256\276\350\256\241\351\227\256\351\242\230\347\232\204\346\226\271\345\274\217.md"
new file mode 100644
index 0000000..4eb7f47
--- /dev/null
+++ "b/src/main/java/com/shenyy/introduction/1.6\350\256\276\350\256\241\346\250\241\345\274\217\350\247\243\345\206\263\350\256\276\350\256\241\351\227\256\351\242\230\347\232\204\346\226\271\345\274\217.md"
@@ -0,0 +1,267 @@
+## 设计模式解决设计问题的方式
+
+### 一、寻找合适的对象
+
+面向对象设计最困难的部分是将系统分解成对象集合。
+
+因为要考虑许多因素:封装、粒度、依赖关系、灵活性、性能、演化、复用等等,它们都影响着系统的分解,并且这些因素
+通常还是互相冲突的。
+
+面向对象设计方法学支持许多设计方法。
+
+你可以写出一个问题描述,挑出名词和动词,
+进而创建相应的类和操作;或者,你可以关注于系统的协作和职责关系;或者,你可以对现实世界建模,再将分析时发现的对象转化至设计中。
+
+设计的许多对象来源于现实世界的分析模型。
+
+但是,设计结果所得到的类通常在现实世
+界中并不存在,有些是像数组之类的低层类,而另一些则层次较高。
+
+例如,Composite(4.3) 模式引入了统一对待现实世界中并不存在的对象的抽象方法。
+
+严格反映当前现实世界的模型并不能产生也能反映将来世界的系统。
+
+设计中的抽象对于产生灵活的设计是至关重要的。
+
+设计模式帮你确定并不明显的抽象和描述这些抽象的对象。
+
+例如,描述过程或算法的对象现实中并不存在,但它们却是设计的关键部分。
+
+Strategy(5.9) 模式描述了怎样实现可互换的
+算法族。
+
+State(5.8)模式将实体的每一个状态描述为一个对象。
+
+这些对象在分析阶段,甚至在
+设计阶段的早期都并不存在,后来为使设计更灵活、复用性更好才将它们发掘出来。
+
+### 二、决定对象的粒度
+
+- Facade(4.5) 模式描述了怎样用对象表示完整的子系统
+- Flyweight(4.6)模式描述了如何支持大量的最小粒度的对象。
+
+其他一些设计模式描述了将一个
+对象分解成许多小对象的特定方法。
+
+- AbstractFactory(3.1)和Builder(3.2)产生那些专门负责生成其他对象的对象。
+- Visitor(5.10)和Command(5.2)生成的对象专门负责实现对其他对象或对象
+ 组的请求。
+
+### 三、指定对象接口
+
+#### 对象接口
+
+对象声明的每一个操作指定操作名、作为参数的对象和返回值,这就是所谓的操作的型构(signature)。
+
+对象操作所定义的所有操作型构的集合被称为该对象的接口(interface)。
+
+对象接口描述了该对象所能接受的全部请求的集合,任何匹配对象接口中型构的请求都可以发送给该对象。
+
+#### 类型
+
+类型(type)是用来标识特定接口的一个名字。
+
+如果一个对象接受“Window”接口所定义的所有操作请求,那么我们就说该对象具有“Window”类型。
+
+#### 对象接口 VS 类型
+
+一个对象可以有许多类型,并且不同的对象可以共享同一个类型。对象接口的某部分可以用某个类型来刻画,而其他部分
+则可用其他类型刻画。两个类型相同的对象只需要共享它们的部分接口。接口可以包含其他接口作为子集。当一个类型的接口包含另一个类型的接口时,我们就说它是另一个类型的子
+类型(subtype),另一个类型称之为它的超类型(supertype)。我们常说子类型继承了它的超类型的接口。
+
+#### 设计模式 VS 接口
+
+设计模式通过确定接口的主要组成成分及经接口发送的数据类型,来帮助你定义接口。
+
+设计模式也许还会告诉你接口中不应包括哪些东西。
+
+Memento(5.6)模式是一个很好的例子,
+它描述了怎样封装和保存对象内部的状态,以便一段时间后对象能恢复到这一状态。它规定
+了Memento对象必须定义两个接口:一个允许客户保持和复制memento的限制接口,和一个只
+有原对象才能使用的用来储存和提取memento中状态的特权接口。
+
+设计模式也指定了接口之间的关系。特别地,它们经常要求一些类具有相似的接口;或
+它们对一些类的接口做了限制。
+
+例如,Decorator(4.4)和Proxy(4.7)模式要求Decorator和Proxy
+对象的接口与被修饰的对象和受委托的对象一致。而Visitor(5.11)模式中,Visitor接口必须反
+映出visitor能访问的对象的所有类。
+
+### 四、描述对象的实现
+
+#### 对象
+
+对象的实现是由它的类决定的,类指定了对象的内部数据和表示,也定义了对象所能完成的操作。
+
+对象通过实例化类来创建,此对象被称为该类的实例。当实例化类时,要给对象的内部数据(由实例变量组成)分配存储空间,并将操作与这些数据联系起来。
+
+#### 类继承(class inheritance)
+
+新的类可以由已存在的类通过类继承(class inheritance)来定义。
+
+当子类(sub class)继承父类(parent class)时,子类包含了父类定义的所有数据和操作。
+
+子类的实例对象包含所有子类和父类定义的数据,且它们能完成子类和父类定义的所有操作。
+
+#### 抽象类(abstract class)
+
+抽象类(abstract class)的主要目的是为它的子类定义公共接口。
+
+一个抽象类将把它的部分或全部操作的实现延迟到子类中,因此,一个抽象类不能被实例化。
+
+在抽象类中定义却没有实现的操作被称为抽象操作(abstract operation)。
+
+非抽象类称为具体类(concrete class)。
+
+#### 重定义(override)
+
+子类能够改进和重新定义它们父类的操作。
+
+更具体地说,类能够重定义(override)父类定义的操作,重定义使得子类能接管父类对请求的处理操作。
+
+类继承允许你只需简单的扩展其他类就可以定义新类,从而可以很容易地定义具有相近功能的对象族。
+
+#### 类继承与接口继承的比较
+
+一个对象的类定义了对象是怎样实现的,同时也定义了对象的内部状态和操作的实现。
+
+但是对象的类型只与它的接口有关,接口即对象能响应的请求的集合。
+
+一个对象可以有多个类型,不同类的对象可以有相同的类型。
+
+##### 类继承与接口继承的区别
+
+- **类继承** 根据一个对象的实现定义了另一个对象的实现。简而言之,它是代码和表示的共享机制。
+- **接口继承** (或子类型化)描述了一个对象什么时候能被用来替代另一个对象。
+
+##### 对接口编程,而不是对实现编程
+
+只根据抽象类中定义的接口来操纵对象有以下两个好处:
+
+1. 客户无须知道他们使用对象的特定类型,只须对象有客户所期望的接口。
+2. 客户无须知道他们使用的对象是用什么类来实现的,他们只须知道定义接口的抽象类。
+
+不将变量声明为某个特定的具体类的实例对象,而是让它遵从抽象类所定义的接口。
+
+### 五、运用复用机制
+
+#### 1. 继承和组合的比较
+
+面向对象系统中功能复用的两种最常用技术是类继承和对象组合:
+
+- 类继承允许你根据其他类的实现来定义一个类的实现。这种通过生成子
+ 类的复用通常被称为白箱复用(white-box reuse)。术语“白箱”是相对可视性而言:在继承方
+ 式中,父类的内部细节对子类可见。
+- 对象组合要求被组合的对象具有良好定义的接口。这种复用风格被称为黑箱复用
+ (black-box reuse),因为对象的内部细节是不可见的。
+
+#### 2. 委托
+
+委托(delegation)是一种组合方法,它使组合具有与继承同样的复用能力。
+
+在委托方式下,有两个对象参与处理一个请求,接受请求的对象将操作委托给它的代理者
+(delegate)。
+
+这类似于子类将请求交给它的父类处理。
+
+委托的主要优点在于它便于运行时刻组合对象操作以及改变这些操作的组合方式。
+
+#### 3. 继承和参数化类型的比较
+
+另一种功能复用技术(并非严格的面向对象技术)是参数化类型(parameterized type)。
+
+它允许你在定义一个类型时并不指定该类型所用到的其他所有类型。未经指定的类型在使用时以参数形式提供。
+
+#### 4. 比较
+
+- 对象组合技术允许你在运行时刻改变被组合的行为,
+ 但是它存在间接性,比较低效。
+- 继承允许你提供操作的缺省实现,并通过子类重定义这些操
+ 作。
+- 参数化类型允许你改变类所用到的类型。但是继承和参数化类型都不能在运行时刻改变。
+
+哪一种方法最佳,取决于你设计和实现的约束条件。
+
+### 六、关联运行时刻和编译时刻的结构
+
+一个面向对象程序运行时刻的结构通常与它的代码结构相差较大:
+
+- 代码结构在编译时刻
+ 就被确定下来了,它由继承关系固定的类组成。
+- 程序的运行时刻结构是由快速变化的通信
+ 对象网络组成。
+
+### 七、设计应支持变化
+
+获得最大限度复用的关键在于对新需求和已有需求发生变化时的预见性,要求你的系统设计要能够相应地改进。
+
+为了设计适应这种变化、且具有健壮性的系统,你必须考虑系统在它的生命周期内会发生怎样的变化。
+
+设计模式可以确保系统能以特定方式变化,从而帮助你避免重新设计系统。
+
+每一个设计模式允许系统结构的某个方面的变化独立于其他方面,这样产生的系统对于某一种特殊变化将更健壮。
+
+#### 导致重新设计的一般原因
+
+下面阐述了一些导致重新设计的一般原因,以及解决这些问题的设计模式:
+
+1. 通过显式地指定一个类来创建对象在创建对象时指定类名将使你受特定实现的约束而不是特定接口的约束。这会使未来的变化更复杂。要避免这种情况,应该间接地创建对象。
+设计模式:AbstractFactory(3.1),FactoryMethod(3.3),Prototype(3.4)。
+2. 对特殊操作的依赖当你为请求指定一个特殊的操作时,完成该请求的方式就固定下来了。为避免把请求代码写死,你将可以在编译时刻或运行时刻很方便地改变响应请求的方法。
+设计模式:ChainofResposibility(5.1),Command(5.2)。
+3. 对硬件和软件平台的依赖外部的操作系统接口和应用编程接口(API)在不同的软硬件平台上是不同的。依赖于特定平台的软件将很难移植到其他平台上,甚至都很难跟上本地平台的更新。所以设计系统时限制其平台相关性就很重要了。
+设计模式:AbstractFactory(3.1),Bridge(4.2)。
+4. 对对象表示或实现的依赖知道对象怎样表示、保存、定位或实现的客户在对象发生变化时可能也需要变化。对客户隐藏这些信息能阻止连锁变化。
+设计模式:AbstractFactory(3.1),Bridge(4.2),Memento(5.6),Proxy(4.7)
+5. 算法依赖算法在开发和复用时常常被扩展、优化和替代。依赖于某个特定算法的对象在算法发生变化时不得不变化。因此有可能发生变化的算法应该被孤立起来。
+设计模式:Builder(3.2),Iterator(5.4),Strategy(5.9),TemplateMethod(5.10),Visitor(5.11)
+6. 紧耦合紧耦合的类很难独立地被复用,因为它们是互相依赖的。紧耦合产生单块的系统,要改变或删掉一个类,你必须理解和改变其他许多类。这样的系统是一个很难学习、移植和维护的密集体。松散耦合提高了一个类本身被复用的可能性,并且系统更易于学习、移植、修改和扩展。设计模式使用抽象耦合和分层技术来提高系统的松散耦合性。
+设计模式:AbstractFactory(3.1),Command(5.2),Facade(4.5),Mediator(5.5),Observer(5.7),ChainofResponsibility(5.1)。
+7. 通过生成子类来扩充功能通常很难通过定义子类来定制对象。每一个新类都有固定的实现开销(初始化、终止处理等)。定义子类还需要对父类有深入的了解。如,重定义一个操作可能需要重定义其他操作。一个被重定义的操作可能需要调用继承下来的操作。并且子类方法会导致类爆炸,因为即使对于一个简单的扩充,你也不得不引入许多新的子类。一般的对象组合技术和具体的委托技术,是继承之外组合对象行为的另一种灵活方法。新的功能可以通过以新的方式组合已有对象,而不是通过定义已存在类的子类的方式加到应用中去。另一方面,过多使用对象组合会使设计难于理解。许多设计模式产生的设计中,你可以定义一个子类,且将它的实例和已存在实例进行组合来引入定制的功能。
+设计模式:Bridge(4.2),ChainofResponsibility(5.1),Composite(4.3),Decorator(4.4),Observer(5.7),Strategy(5.9)。
+8. 不能方便地对类进行修改有时你不得不改变一个难以修改的类。也许你需要源代码而又没有(对于商业类库就有这种情况),或者可能对类的任何改变会要求修改许多已存在的其他子类。设计模式提供在这些情况下对类进行修改的方法。
+设计模式:Adapter(4.1),Decorator(4.4),Visitor(5.11)。
+
+#### 设计模式在开发中所起的作用
+
+##### 应用程序
+
+应用程序 (Application Program) 的内部复用性、可维护性和可扩充性是要优先考虑的:
+
+- 内部复用性确保你不会做多余的
+ 设计和实现。设计模式通过减少依赖性来提高内部复用性。松散耦合也增强了一类对象与其
+ 他多个对象协作的可能性。
+- 当设计模式被用来对系统分层和限制对平台的依赖性时,它们还会使一个应用更具可维
+ 护性。
+- 通过显示怎样扩展类层次结构和怎样使用对象复用,它们可增强系统的易扩充性。同时,耦合程度的降低也会增强可扩充性。如果一个类不过多地依赖其他类,扩充这个孤立的类还是很容易的。
+
+##### 工具箱
+
+工具箱( Toolkit )的设计比应用设计要难得多,因为它要求对许多应用是可用的和有效的。
+
+再者,
+工具箱的设计者并不知道什么应用使用该工具箱及它们有什么特殊需求。
+
+这样,避免假设和
+依赖就变得很重要,否则会限制工具箱的灵活性,进而影响它的适用性和效率。
+
+##### 框架
+
+框架(Framework)是构成一类特定软件可复用设计的一组相互协作的类。
+
+框架规定了你的应用的体系结构。它定义了整体结构,类和对象的分割,各部分的主要
+责任,类和对象怎么协作,以及控制流程。框架预定义了这些设计参数,以便于应用设计者
+或实现者能集中精力于应用本身的特定细节。框架记录了其应用领域的共同的设计决策。因而框架更强调设计复用,尽管框架常包括具体的立即可用的子类。
+
+#### 模式和框架的不同
+
+- **设计模式比框架更抽象** 框架能够用代码表示,而设计模式只有其实例才能表示为代
+ 码。框架的威力在于它们能够使用程序设计语言写出来,它们不仅能被学习,也能被直接执
+ 行和复用。
+- **设计模式是比框架更小的体系结构元素** 一个典型的框架包括了多个设计模式,而反
+ 之决非如此。
+- **框架比设计模式更加特例化** 框架总是针对一个特定的应用领域。一个图形编辑器框
+ 架可能被用于一个工厂模拟,但它不会被错认为是一个模拟框架。
+
+
+
diff --git "a/src/main/java/com/shenyy/introduction/1.7\346\200\216\346\240\267\351\200\211\346\213\251\350\256\276\350\256\241\346\250\241\345\274\217.md" "b/src/main/java/com/shenyy/introduction/1.7\346\200\216\346\240\267\351\200\211\346\213\251\350\256\276\350\256\241\346\250\241\345\274\217.md"
new file mode 100644
index 0000000..3dbd361
--- /dev/null
+++ "b/src/main/java/com/shenyy/introduction/1.7\346\200\216\346\240\267\351\200\211\346\213\251\350\256\276\350\256\241\346\250\241\345\274\217.md"
@@ -0,0 +1,27 @@
+## 怎样选择设计模式
+
+### 选择设计模式的方法
+
+- **考虑设计模式是怎样解决设计问题的** [1.6设计模式解决设计问题的方式](1.6设计模式解决设计问题的方式.md) 讨论了设计模式怎样帮助你找到合适的对象、决定对象的粒度、指定对象接口以及设计模式解决设计问题的几个其他方法。参考这些讨论会有助于你找到合适的模式。
+- **浏览模式的意图部分** [1.4设计模式的分类](1.4设计模式的分类.md) 列出了目录中所有模式的意图(intent)部分。通读每个模式的
+ 意图,找出和你的问题相关的一个或多个模式。
+- **研究模式怎样互相关联** 研究设计模式之间的关系
+ 能指导你获得合适的模式或模式组。
+- **研究目的相似的模式** 模式分类描述部分共有三章,一章介绍创建型模式,一章介绍结
+ 构型模式,一章介绍行为型模式。每一章都以对模式介绍性的评价开始,以一个小节的
+ 比较和对照结束。这些小节使你得以洞察具有相似目的的模式之间的共同点和不同点。
+- **检查重新设计的原因** 看一看从“设计应支持变化”小节开始讨论的引起重新设计的各
+ 种原因,再看看你的问题是否与它们有关,然后再找出哪些模式可以帮助你避免这些会
+ 导致重新设计的因素。
+- **考虑你的设计中哪些是可变的** 这个方法与关注引起重新设计的原因刚好相反。它不是
+ 考虑什么会迫使你的设计改变,而是考虑你想要什么变化却又不会引起重新设计。最主
+ 要的一点是封装变化的概念,这是许多设计模式的主题。
+
+### 设计模式之间的关系
+
+
+
+### 设计模式所支持的设计的可变方面
+
+
+
diff --git "a/src/main/java/com/shenyy/introduction/1.8\346\200\216\346\240\267\344\275\277\347\224\250\350\256\276\350\256\241\346\250\241\345\274\217.md" "b/src/main/java/com/shenyy/introduction/1.8\346\200\216\346\240\267\344\275\277\347\224\250\350\256\276\350\256\241\346\250\241\345\274\217.md"
new file mode 100644
index 0000000..136df44
--- /dev/null
+++ "b/src/main/java/com/shenyy/introduction/1.8\346\200\216\346\240\267\344\275\277\347\224\250\350\256\276\350\256\241\346\250\241\345\274\217.md"
@@ -0,0 +1,31 @@
+## 怎样使用设计模式
+
+### 应用设计模式的方法
+
+应用设计模式的循序渐进的方法:
+
+1. **大致浏览一遍模式** 特别注意其适用性部分和效果部分,确定它适合你的问题。
+2. **回头研究结构部分、参与者部分和协作部分** 确保你理解这个模式的类和对象以及它
+ 们是怎样关联的。
+3. **看代码示例部分,看看这个模式代码形式的具体例子** 研究代码将有助于你实现模式。
+4. **选择模式参与者的名字,使它们在应用上下文中有意义** 设计模式参与者的名字通常过于抽象而不会直接出现在应用中。然而,将参与者的名字和应用中出现的名字合并起来是
+ 很有用的。这会帮助你在实现中更显式的体现出模式来。例如,如果你在文本组合算法中使
+ 用了Strategy模式,那么你可能有名为SimpleLayoutStrategy或TeXLayoutStrategy这样的类。
+5. **定义类** 声明它们的接口,建立它们的继承关系,定义代表数据和对象引用的实例变
+ 量。识别模式会影响到的你的应用中存在的类,做出相应的修改。
+6. **定义模式中专用于应用的操作名称** 这里再一次体现出,名字一般依赖于应用。使用
+ 与每一个操作相关联的责任和协作作为指导。还有,你的名字约定要一致。例如,可以使用
+ “Create-”前缀统一标记Factory方法。
+7. **实现执行模式中责任和协作的操作** 实现部分提供线索指导你进行实现。代码示例部
+ 分的例子也能提供帮助。
+
+### 设计模式的使用限制
+
+设计模式不能够随意使用。
+
+通常你通过引入额外的间接层次获得灵活性和可变性的同
+时,你也使设计变得更复杂并 /或牺牲了一定的性能。
+
+一个设计模式只有当它提供的灵活性是
+真正需要的时候,才有必要使用。
+
diff --git "a/src/main/java/com/shenyy/introduction/1.9\347\233\270\345\205\263\350\257\215\346\261\207\350\241\250.md" "b/src/main/java/com/shenyy/introduction/1.9\347\233\270\345\205\263\350\257\215\346\261\207\350\241\250.md"
new file mode 100644
index 0000000..d30ef91
--- /dev/null
+++ "b/src/main/java/com/shenyy/introduction/1.9\347\233\270\345\205\263\350\257\215\346\261\207\350\241\250.md"
@@ -0,0 +1,142 @@
+## 相关词汇表
+
+- **抽象类(abstract class)**
+一种主要用来定义接口的类。抽象类中的部分或全部操作被延迟到其子类中实现。抽象类不能实例化。
+
+- **抽象耦合(abstract coupling)**
+若类A维护一个指向抽象类B的引用,则称类A抽象耦合于B。我们之所以称之为抽象耦合乃是因为A指向的是一个对象的类型,而不是一个具体对象。
+
+- **抽象操作(abstract operation)**
+一种声明了型构(signature)而没有实现的操作。在C++中,抽象操作对应于纯虚成员函数。
+
+- **相识关系(acquaintance relationship)**
+如果一个类指向另一个类,则这两个类之间有相识关系。
+
+- **聚合对象(aggregate object)**
+一种包含子对象的对象。这些子对象称为聚合对象的部分,而聚合对象对它们负责。
+
+- **聚合关系(aggregation relationship)**
+聚合对象与其部分之间的关系。类为其对象(例如,聚合对象)定义这种关系。
+
+- **黑箱复用(black-boxreuse)**
+一种基于对象组合的复用方式。这些被组合的对象之间并不开放各自的内部细节,因此被比作“黑箱”。
+
+- **类(class)**
+类定义对象的接口和实现。它规定对象的内部表示,定义对象可实施的操作。
+
+- **类图(class diagram)**
+类图描述类及其内部结构和操作,以及类间的静态关系。
+
+- **类操作(class operation)**
+以类而不是单独的对象为目标的操作。在C++中,类操作称为静态成员函数。
+
+- **具体类(concrete class)**
+不含抽象操作的类。它可以实例化。
+
+- **构造器(constructor)**
+在C++中,一种系统自动调用的用来初始化新对象实例的操作。
+
+- **耦合(coupling)**
+软件构件之间相互依赖的程度。
+
+- **委托(delegation)**
+一种实现机制,即一个对象把发给它的请求转发/委托给另一个对象。而受托对象将代表原对象执行请求的操作。
+
+- **设计模式(design pattern)**
+设计模式针对面相对象系统中重复出现的设计问题,提出一个通用的设计方案,并予以系统化的命名和动机解释。它描述了问题、解决方案、在什么条件下使用该解决方案及其效果。它还给出了实现要点和实例。该解决方案是解决该问题的一组精心安排的通用的类和对象,再经定制和实现就可用来解决特定上下文中的问题。
+
+- **析构器(destructor)**
+在C++中,一种系统自动调用的用来清理(finalize)即将被删除的对象的操作。
+
+- **动态绑定(dynamic binding)**
+在运行时刻才将一个请求与一个对象及其一个操作关联起来。在C++中,只有虚函数可动态绑定。
+
+- **封装(encapsulation)**
+其结果是将对象的表示和实现隐藏起来。在对象之外,看不到其内部表示,也不能直接对其进行访问。操作(operation)是访问和修改对象表示的唯一途径。
+
+- **框架(framework)**
+一组相互协作的类,形成某类软件的一个可复用设计。框架将设计划分为一组抽象类,并定义它们各自的责任及相互之间的合作,以此来指导体系结构级的设计。开发者通过继承框架中的类和组合其实例来定制该框架以生成特定的应用。
+
+- **友类(friend class)**
+在C++中,A为B的友类是指A对B中的操作和数据有与B本身一样的访问权限。
+
+- **继承(inheritance)**
+两个实体间的一种关系,其中一实体乃是基于另一实体而定义的。类继承以一个或多个父类为基础定义一个新类,这个新类继承了其父类的接口和实现,被称为子类或派生类。类继承包含了接口继承和实现继承。接口继承以一个或多个已有接口为基础定义新的接口;实现继承以一个或多个已有实现为基础定义新的实现。
+
+- **实例变量(instance variable)**
+定义部分对象表示的数据。C++中使用的术语是数据成员。
+
+- **交互图(interaction diagram)**
+展示对象间请求流程的一种示意图。
+
+- **接口(interface)**
+一个对象所有操作定义的型构的集合。接口刻划了一个对象可响应的请求的集合。
+
+- **元类(metaclass)**
+在Smalltalk中,类也是对象。元类是类对象的类。
+
+- **混入类(mixin class)**
+一种被设计为通过继承与其他类结合的类。混入类通常是抽象类。
+
+- **对象(object)**
+一个封装了数据及作用于这些数据的操作的运行实体。
+
+- **对象组合(object composition)**
+组装和组合一组对象以获得更复杂的行为。
+
+- **对象图(object diagram)**
+描述运行时刻特定对象结构的示意图。
+
+- **对象引用(object reference)**
+用于标识另一对象的一个值。
+
+- **操作(operation)**
+对象的数据仅能由其自身的操作来存取。对象受到请求时执行操作。在C++中,操作称为成员函数,而Smalltalk使用术语“方法”。
+
+- **重定义(overriding)**
+在一个子类中重定义(从父类继承下来的)操作。
+
+- **参数化类型(parameterized type)**
+一种含有未确定成分类型的类型。在使用时,将未确定类型处理成参数。在C++中,参数化类型称为模板(template)。
+
+- **父类(parent class)**
+被其他类继承的类。Smalltalk又称之为超类(super class),C++中又称之为基类(base class),有时又称为祖先类(ancestor class)。
+
+- **多态(polymorphism)**
+在运行时刻接口匹配的对象能互相替换的能力。
+
+- **私有继承(private inheritance)**
+在C++中,一种仅出于实现目的的继承。
+
+- **协议(protocol)**
+接口概念的扩展,包含指明可允许的请求序列。
+
+- **接收者(receiver)**
+一个请求的目标对象。
+
+- **请求(request)**
+一个对象当受到其他对象的请求时执行相应的操作。通常请求又称为消息。
+
+- **型构(signature)**
+一个操作的型构定义了它的名称、参数和返回值。
+
+- **子类(subclass)**
+继承了另一个类的类。在C++中,子类又称为派生类(derivedclass)。
+
+- **子系统(subsystem)**
+一组相互协作的类形成的一个相对独立的部分,完成一定的功能。
+
+- **子类型(subtype)**
+如果一个类型的接口包含另一类型的接口,则前一类型称为后一类型的子类型。
+
+- **超类型(supertype)**
+为其他类型继承的父类型。
+
+- **工具箱(toolkit)**
+一组提供实用功能的类,但它们并不包含任何具体应用的设计。
+
+- **类型(type)**
+一个特定接口的名称。
+
+- **白箱复用(white-box reuse)**
+一种基于类继承的复用。子类复用父类的接口和实现,但它也可能存取其父类的其他私有部分。
\ No newline at end of file
diff --git a/src/main/java/com/shenyy/introduction/assets/1563363834415.png b/src/main/java/com/shenyy/introduction/assets/1563363834415.png
new file mode 100644
index 0000000..df0142f
Binary files /dev/null and b/src/main/java/com/shenyy/introduction/assets/1563363834415.png differ
diff --git a/src/main/java/com/shenyy/introduction/assets/1563430491628.png b/src/main/java/com/shenyy/introduction/assets/1563430491628.png
new file mode 100644
index 0000000..8c4a025
Binary files /dev/null and b/src/main/java/com/shenyy/introduction/assets/1563430491628.png differ
diff --git a/src/main/java/com/shenyy/introduction/assets/1563431139090.png b/src/main/java/com/shenyy/introduction/assets/1563431139090.png
new file mode 100644
index 0000000..a94b187
Binary files /dev/null and b/src/main/java/com/shenyy/introduction/assets/1563431139090.png differ
diff --git a/src/main/java/com/shenyy/introduction/assets/1563880582136.png b/src/main/java/com/shenyy/introduction/assets/1563880582136.png
new file mode 100644
index 0000000..89bf2b5
Binary files /dev/null and b/src/main/java/com/shenyy/introduction/assets/1563880582136.png differ
diff --git a/src/main/resources/app.xml b/src/main/resources/app.xml
index 0f11269..759c15f 100644
--- a/src/main/resources/app.xml
+++ b/src/main/resources/app.xml
@@ -9,19 +9,19 @@
-
-
+
+
-
+
diff --git a/src/main/resources/app_auto.xml b/src/main/resources/app_auto.xml
index 2b7ac68..b55ebe6 100644
--- a/src/main/resources/app_auto.xml
+++ b/src/main/resources/app_auto.xml
@@ -9,8 +9,8 @@
-
+
diff --git a/src/test/java/com/shenyy/dp/proxy/chatgpt/RealInternetTest.java b/src/test/java/com/shenyy/dp/proxy/chatgpt/RealInternetTest.java
new file mode 100644
index 0000000..a8e0b3a
--- /dev/null
+++ b/src/test/java/com/shenyy/dp/proxy/chatgpt/RealInternetTest.java
@@ -0,0 +1,14 @@
+package com.shenyy.dp.proxy.chatgpt;
+
+class RealInternetTest {
+
+ @org.junit.jupiter.api.Test
+ void connectTo() {
+ RealInternet realInternet = new RealInternet();
+ try {
+ realInternet.connectTo("baidu.com");
+ } catch (Exception e) {
+ System.out.println(e.getMessage());
+ }
+ }
+}
\ No newline at end of file