- 博客(23)
- 收藏
- 关注
原创 迭代器模式一步步实现
//加薪代码初步/*class Request{ private String requestType; private String requestContent; private int num; public String getRequestType() { return requestType; } public void setRequestType(String requestType) { this.requestType = requestType; } publ
2020-06-09 22:10:48 104
原创 命令模式一步步实现
/*class Barbecuer{ public void BakeMutton() { System.out.println("烤羊肉串"); } public void BakeChickenWing() { System.out.println("烤鸡翅"); }}public class Main { public static void main(String args[]) { Barbecuer b = new Barbecuer(); b.B
2020-06-09 22:09:43 147
翻译 组合模式一步步实现
//未用模式/*class Leaf{ private String name; public Leaf(String name) { super(); this.name = name; } public void printStruct(int d) for(int i=0;i<d;i++) { System.out.print(" "); System.out.println("-"+name); }}class Composite{ private
2020-06-03 00:51:43 78
原创 备忘录模式 一步步实现
//游戏存进度/*class GameRole{ private int vit; public int getVit() { return vit; } public void setVit(int vit) { this.vit = vit; } private int atk; public int getAtk() { return atk; } public void setAtk(int atk) { this.atk = atk; } private i
2020-06-02 23:57:06 111
原创 状态模式一步步实现
//工作状态 函数版/*public class Main { static int Hour = 0; static boolean WorkFinished = false; public static void WriteProgram() { if(Hour < 12) { System.out.println("当前时间:"+Hour+"点,上午工作,精神百倍"); } else if(Hour < 13) { System.out.println("
2020-06-02 23:07:50 74
原创 观察者模式2
import java.util.ArrayList;abstract class Subject{ private ArrayList<ConcreteObserver> observers = new ArrayList<ConcreteObserver>(); public void Attach(ConcreteObserver concreteObserver) { observers.add(concreteObserver); } public void
2020-06-02 21:45:37 71
原创 观察者模式1
/*双向耦合代码public class Main { public static void main(String args[]) { Secretary s = new Secretary(); StockObserver s1 = new StockObserver("小明",s); StockObserver s2 = new StockObserver("小红",s); s.Attach(s1); s.Attach(s2); s.set
2020-06-02 21:35:33 70
原创 外观模式一步步实现
//股民炒股代码/*class Stock1{ public void Sell() { System.out.println("股票1卖出"); } public void Buy() { System.out.println("股票1买入"); }}class Stock2{ public void Sell() { System.out.println("股票2卖出"); } public void Buy() { System.out.println("股票2买入
2020-05-12 23:34:29 77
原创 桥接模式 实现
//紧耦合/*public class Main { public static void main(String args[]) { HandsetBrand hb; hb= new HandsetBrandMAddressList(); hb.Ran(); hb=new HandsetBrandMGame(); hb.Ran(); ...
2020-04-28 21:05:43 118
原创 中介者模式
//中介者模式/*abstract class Mediator{ public abstract void Send(String message,Colleague colleague);}abstract class Colleague{ protected Mediator mediator; public Colleague(Mediator mediator) { su...
2020-04-28 20:17:23 67
原创 适配器模式
//篮球翻译适配器public class Main { public static void main(String args[]) { Player f=new Forwards("巴蒂尔"); f.Attack(); Player g=new Guards("麦克格雷迪"); g.Attack(); Player c=new Center...
2020-04-28 20:16:27 56
原创 适配器模式
//篮球翻译适配器public class Main { public static void main(String args[]) { Player f=new Forwards("巴蒂尔"); f.Attack(); Player g=new Guards("麦克格雷迪"); g.Attack(); Player c=new Center...
2020-04-25 23:20:54 60
原创 代理模式一步步实现
//第一版没有代理模式/*public class Main { public static void main(String args[]) { SchoolGirl ss=new SchoolGirl("李娇娇"); Pursuit zhuo=new Pursuit("卓嘉义"); Pursuit zhuo=new Pursuit(ss); zhu...
2020-04-25 19:31:42 76
原创 装饰模式一步步实现
//第一版/*public class Main { public static void main(String args[]) { Person p=new Person("小菜"); System.out.println("第一种装扮"); p.WearTShirt(); p.WearBigTrouser(); p.WearSneaker...
2020-04-25 17:05:50 61
原创 单例模式锁定
public class Main { public static void main(String args[]) { Singleton s1=Singleton.GetInstance(); Singleton s2=Singleton.GetInstance(); if(s1==s2) { System.out.println("两个对象是相同的实例"...
2020-04-14 20:30:03 75
原创 单例模式
public class Main { public static void main(String args[]) { Singleton s1=Singleton.GetInstance(); Singleton s2=Singleton.GetInstance(); if(s1==s2) { System.out.println("两个对象是相同的实例"); ...
2020-04-14 20:26:01 53
原创 享元模式
public class Main { public static void main(String args[]) { int extrinsicstate=22; FlyweightFactory f=new FlyweightFactory(); Flyweight fx=f.GetFlyweight(0); fx.Operation(--extrinsicsta...
2020-04-14 20:21:40 57
原创 建造者模式
public class Main { public static void main(String args[]) { Director d=new Director(); Builder b1=new ConcreteBuilder1(); Builder b2=new ConcreteBuilder2(); d.Construct(b1); Product p...
2020-04-07 21:18:13 55
原创 原型模式
public class Main { public static void main(String args[]) { Resume a=new Resume("大鸟"); a.SetPersonalInfo("男", "29"); a.SetWorkExperience("1998-2000", "XX公司"); Resume b=(Resume)...
2020-04-07 19:59:37 52
原创 抽象工厂
class Department{ int id;}interface IDepartment{ void Insert(Department department); Department GetDepartment(int id);}class SqlserverDepartment implements IDepartment{ public void Insert(Depa...
2020-03-31 22:03:17 59
原创 工厂方法
abstract class Operation { double NumberA; double NumberB; public double getNumberA() { return NumberA; } public double getNumberB() { return NumberB; } public abstract doubl...
2020-03-31 20:56:02 126
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人