提交 46d3e4c3 编写于 作者: C chenjianqiang

11-24复习

上级 7cb10c8d
...@@ -2,8 +2,10 @@ ...@@ -2,8 +2,10 @@
<project version="4"> <project version="4">
<component name="ChangeListManager"> <component name="ChangeListManager">
<list default="true" id="e43e9168-5945-4f45-b4c2-1b6410d1eef8" name="Changes" comment="增加策略模式案例&#10;Signed-off-by: chenjianqiang &lt;wushanxi@gmail.com&gt;"> <list default="true" id="e43e9168-5945-4f45-b4c2-1b6410d1eef8" name="Changes" comment="增加策略模式案例&#10;Signed-off-by: chenjianqiang &lt;wushanxi@gmail.com&gt;">
<change beforePath="$PROJECT_DIR$/src/com/pattern/InterpreterPattern/package-info.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/com/pattern/InterpreterPattern/package-info.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/com/pattern/PatternApplication.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/com/pattern/PatternApplication.java" afterDir="false" /> <change beforePath="$PROJECT_DIR$/src/com/pattern/PatternApplication.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/com/pattern/PatternApplication.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/com/pattern/ProxyPattern/ProxyMain.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/com/pattern/ProxyPattern/ProxyMain.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/com/pattern/ProxyPattern/materials/README.md" beforeDir="false" afterPath="$PROJECT_DIR$/src/com/pattern/ProxyPattern/materials/README.md" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/com/pattern/ProxyPattern/materials/po/YellowBullHandler.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/com/pattern/ProxyPattern/materials/po/YellowBullHandler.java" afterDir="false" />
</list> </list>
<option name="SHOW_DIALOG" value="false" /> <option name="SHOW_DIALOG" value="false" />
<option name="HIGHLIGHT_CONFLICTS" value="true" /> <option name="HIGHLIGHT_CONFLICTS" value="true" />
...@@ -90,7 +92,11 @@ ...@@ -90,7 +92,11 @@
<option name="showLibraryContents" value="true" /> <option name="showLibraryContents" value="true" />
</component> </component>
<component name="PropertiesComponent"> <component name="PropertiesComponent">
<property name="RunOnceActivity.OpenProjectViewOnStart" value="true" />
<property name="RunOnceActivity.ShowReadmeOnStart" value="true" />
<property name="WebServerToolWindowFactoryState" value="false" /> <property name="WebServerToolWindowFactoryState" value="false" />
<property name="go.formatter.settings.were.checked" value="true" />
<property name="go.import.settings.migrated" value="true" />
<property name="last_opened_file_path" value="$PROJECT_DIR$/src/com/pattern" /> <property name="last_opened_file_path" value="$PROJECT_DIR$/src/com/pattern" />
<property name="settings.editor.selected.configurable" value="editor.preferences.import" /> <property name="settings.editor.selected.configurable" value="editor.preferences.import" />
<property name="typescript.add.unambiguous.imports.on.the.fly" value="true" /> <property name="typescript.add.unambiguous.imports.on.the.fly" value="true" />
...@@ -156,7 +162,8 @@ ...@@ -156,7 +162,8 @@
<workItem from="1634115899707" duration="377000" /> <workItem from="1634115899707" duration="377000" />
<workItem from="1634180031509" duration="3704000" /> <workItem from="1634180031509" duration="3704000" />
<workItem from="1636338443252" duration="4865000" /> <workItem from="1636338443252" duration="4865000" />
<workItem from="1636350581794" duration="2451000" /> <workItem from="1636350581794" duration="2679000" />
<workItem from="1637721077456" duration="1739000" />
</task> </task>
<task id="LOCAL-00001" summary="增加策略模式案例&#10;Signed-off-by: chenjianqiang &lt;wushanxi@gmail.com&gt;"> <task id="LOCAL-00001" summary="增加策略模式案例&#10;Signed-off-by: chenjianqiang &lt;wushanxi@gmail.com&gt;">
<created>1634096220780</created> <created>1634096220780</created>
......
主:官方卖票的地方
代理:将官方买票的构造传进来,然后加上自己的服务然后调用官方的去实现这个功能
package com.pattern; package com.pattern;
import com.pattern.ProxyPattern.ProxyMain;
/** /**
* @author lx * @author lx
*/ */
...@@ -13,6 +11,7 @@ public class PatternApplication { ...@@ -13,6 +11,7 @@ public class PatternApplication {
解释器模式 解释器模式
new InterpreterMain().main(); new InterpreterMain().main();
2021-10-14:制作多个计算规则,用这些规则去拼装组合来实现某些需求 2021-10-14:制作多个计算规则,用这些规则去拼装组合来实现某些需求
2021-11-24:一个接口很多实例的类,其中一个类是终端计算规则,剩下的类传入一个或多个终端计算,并把每一个终端计算结果再进行计算,成为一个单独的计算规则
*/ */
...@@ -21,7 +20,7 @@ public class PatternApplication { ...@@ -21,7 +20,7 @@ public class PatternApplication {
策略模式 策略模式
new StrategyMain().main(); new StrategyMain().main();
2021-10-14:通过构造context传入不同的规则,再给context执行方法传入不同的值进行不同的计算 2021-10-14:通过构造context传入不同的规则,再给context执行方法传入不同的值进行不同的计算
2021-11-24:context作为触发器,传进来不同的策略,然后执行策略里面的方法
*/ */
...@@ -38,7 +37,7 @@ public class PatternApplication { ...@@ -38,7 +37,7 @@ public class PatternApplication {
/* /*
工厂模式 -- 方法工厂 工厂模式 -- 方法工厂
new FunctionFactoryMain().main(); new FunctionFactoryMain().main();
2021-10-14: 2021-10-14: 一个工厂只能造一种产品,也就是一个方法工厂返回一个对象,想要多个对象就要多个工厂
*/ */
...@@ -47,7 +46,7 @@ public class PatternApplication { ...@@ -47,7 +46,7 @@ public class PatternApplication {
/* /*
工厂模式 -- 抽象工厂 工厂模式 -- 抽象工厂
new AbstractFactoryMain().main(); new AbstractFactoryMain().main();
2021-10-14: 2021-10-14: 把工厂抽象,实例化一个工厂定义多个对象的产出,然后实例化这个工厂就可以拿到多个产品
*/ */
...@@ -70,9 +69,10 @@ public class PatternApplication { ...@@ -70,9 +69,10 @@ public class PatternApplication {
*/ */
new ProxyMain().reflectMain();
/* /*
代理模式 代理模式 ---动态代理
new ProxyMain().reflectMain();
代理模式 ---静态代理
new ProxyMain().staticMain(); new ProxyMain().staticMain();
2021-10-14: 2021-10-14:
......
...@@ -36,5 +36,6 @@ public class ProxyMain { ...@@ -36,5 +36,6 @@ public class ProxyMain {
YellowBullHandler handler = new YellowBullHandler(); YellowBullHandler handler = new YellowBullHandler();
TicketService subject = (TicketService) handler.newProxyInstance(beijingStation); TicketService subject = (TicketService) handler.newProxyInstance(beijingStation);
subject.consultation("你们卖票的么?"); subject.consultation("你们卖票的么?");
subject.sellT();
} }
} }
主:官方卖票的地方
代理:将官方买票的构造传进来,然后加上自己的服务然后调用官方的去实现这个功能
...@@ -56,11 +56,13 @@ public class YellowBullHandler implements InvocationHandler { ...@@ -56,11 +56,13 @@ public class YellowBullHandler implements InvocationHandler {
@Override @Override
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable { public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
System.out.println("高级黄牛为你服务..."); System.out.println("...高级黄牛为你服务...");
Object ret; Object ret;
try { try {
if (args != null) {
for (int i = 0; i < args.length; i++) { for (int i = 0; i < args.length; i++) {
System.out.println("参数" + (i + 1) +":"+ args[i]); System.out.println("参数" + (i + 1) + ":" + args[i]);
}
} }
//调用目标方法 //调用目标方法
ret = method.invoke(target, args); ret = method.invoke(target, args);
...@@ -68,7 +70,7 @@ public class YellowBullHandler implements InvocationHandler { ...@@ -68,7 +70,7 @@ public class YellowBullHandler implements InvocationHandler {
System.err.println(target.getClass().getName() + method.getName() + e); System.err.println(target.getClass().getName() + method.getName() + e);
throw e; throw e;
} }
System.out.println("高级黄牛服务结束..."); System.out.println("...高级黄牛服务结束...");
return ret; return ret;
} }
} }
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册