提交 980b6f20 编写于 作者: 门心叼龙's avatar 门心叼龙

code perfect

上级 4948ba80
package com.mxdl.desigin.pattern;
import java.util.ArrayList;
import java.util.Observable;
import java.util.Observer;
......@@ -40,5 +41,7 @@ public class Test {
});
System.out.println("update 22 start...");
observable.notifyObservers("fff");
Iterable iterable;
ArrayList list;
}
}
package com.mxdl.desigin.pattern.behavior.state;
/**
* Description: <Light><br>
* Author: mxdl<br>
* Date: 2019/12/26<br>
* Version: V1.0.0<br>
* Update: <br>
*/
public class Light {
private State state;
public Light(){
state = new StateClose();
}
void onPress(){
state.onPress(this);
}
public void setState(State state) {
this.state = state;
}
}
package com.mxdl.desigin.pattern.behavior.state;
/**
* Description: <State><br>
* Author: mxdl<br>
* Date: 2019/12/26<br>
* Version: V1.0.0<br>
* Update: <br>
*/
public interface State {
void onPress(Light light);
}
package com.mxdl.desigin.pattern.behavior.state;
/**
* Description: <StateClose><br>
* Author: mxdl<br>
* Date: 2019/12/26<br>
* Version: V1.0.0<br>
* Update: <br>
*/
public class StateClose implements State {
@Override
public void onPress(Light light) {
System.out.println("关闭状态");
light.setState(new StateOpen());
}
}
package com.mxdl.desigin.pattern.behavior.state;
/**
* Description: <StateClose><br>
* Author: mxdl<br>
* Date: 2019/12/26<br>
* Version: V1.0.0<br>
* Update: <br>
*/
public class StateOpen implements State {
@Override
public void onPress(Light light) {
System.out.println("打开状态");
light.setState(new StateClose());
}
}
package com.mxdl.desigin.pattern.behavior.state;
import com.mxdl.desigin.pattern.behavior.state.test.MyLight;
/**
* Description: <Test><br>
* Author: mxdl<br>
* Date: 2019/12/26<br>
* Version: V1.0.0<br>
* Update: <br>
*/
public class Test {
public static void main(String[] args) {
// Light light = new Light();
//// light.onPress();
//// light.onPress();
//// light.onPress();
MyLight myLight = new MyLight();
myLight.onPress();
myLight.onPress();
myLight.onPress();
}
}
package com.mxdl.desigin.pattern.behavior.state.test;
/**
* Description: <IState><br>
* Author: mxdl<br>
* Date: 2019/12/26<br>
* Version: V1.0.0<br>
* Update: <br>
*/
public interface IState {
void onPress(MyLight light);
}
package com.mxdl.desigin.pattern.behavior.state.test;
/**
* Description: <MyOpenState><br>
* Author: mxdl<br>
* Date: 2019/12/26<br>
* Version: V1.0.0<br>
* Update: <br>
*/
public class MyCloseState implements IState {
@Override
public void onPress(MyLight light) {
System.out.println("灯打开了");
}
}
package com.mxdl.desigin.pattern.behavior.state.test;
/**
* Description: <MyLight><br>
* Author: mxdl<br>
* Date: 2019/12/26<br>
* Version: V1.0.0<br>
* Update: <br>
*/
public class MyLight {
// boolean isOpen = false;
// public void onPress(){
// if(isOpen){
// System.out.println("灯打开了");
// isOpen = false;
// }else{
// System.out.println("灯关闭了");
// isOpen = true;
// }
// }
IState mIState;
public void onPress(){
mIState.onPress(this);
}
public void setIState(IState IState) {
mIState = IState;
}
}
package com.mxdl.desigin.pattern.behavior.state.test;
/**
* Description: <MyLightState><br>
* Author: mxdl<br>
* Date: 2019/12/26<br>
* Version: V1.0.0<br>
* Update: <br>
*/
public class MyLightState {
}
package com.mxdl.desigin.pattern.behavior.state.test;
import com.mxdl.desigin.pattern.behavior.state.StateOpen;
/**
* Description: <MyOpenState><br>
* Author: mxdl<br>
* Date: 2019/12/26<br>
* Version: V1.0.0<br>
* Update: <br>
*/
public class MyOpenState implements IState {
@Override
public void onPress(MyLight light) {
System.out.println("灯打开了");
light.setIState(new MyCloseState());
}
}
@startuml
skinparam classAttributeSkipSize 0
package "Factory Method" {
abstract class Creator{
+factoryMethod():Product
}
abstract class Product
class ConcreateCreator extends Creator
note top: 定义了一个创建对象的接口,\n 具体的创建类型由子类来完成
abstract class Product
class ConcreateProduct extends Product
ConcreateCreator -> ConcreateProduct
......
......@@ -16,7 +16,7 @@ package "Adapter"{
Adapter ->Adaptee
class Client
note left:1.类适配器\n2.接口适配器\n3.对象适配器
note left:1.接口适配器\n2.对象适配器
Client ->Target
}
......
@startuml
package Bridge{
class Abstraction
note top:抽象
interface Implementor
note top:实现
class Abstraction
note top:抽象
interface Implementor
note top:实现
Abstraction -> Implementor
class ConcreateAbstraction
note bottom:将对象的抽象和实现相分离,使二者可以相对独立的变化
class ConcreateAbstraction extends Abstraction
class ConcreateImplementor implements Implementor
}
@enduml
\ No newline at end of file
......@@ -5,6 +5,7 @@ package Conposite{
+add(paramter:Component)
+remove(paramter:Component)
}
note top:将多个单一对象组成一个具有一定层次关系的树形结构的组合对象\n 组合模式淡化了单个对象和组合对象之间的差别\n使得单个对象和组合对象之间有相同的处理方式
class Leaf implements Component
class Conposite implements Component{
+conponents:List<Component>
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册