- 博客(28)
- 资源 (2)
- 收藏
- 关注
原创 23种设计模式之迭代器模式(行为型,11 Iterator,c++实现)
代码实现:#include <iostream>using namespace std;typedef int Object;#define SIZE 5class Iterator {public:virtual void first() = 0;virtual void next() = 0;virtual bool hasNext() = 0;virtual Object get...
2018-03-25 12:58:10
237
原创 23种设计模式之解释器模式(行为型,10 Interpreter,c++实现)
代码实现:#include <iostream>#include <string>using namespace std;class Context {public:Context(){this->setNum(0);}void setNum(int num){this->num = num;}int getNum(){return this->num;}...
2018-03-25 12:22:12
228
原创 23种设计模式之状态模式(行为型,9 State,c++实现)
#include <iostream>#include <string>using namespace std;class Worker;class State{public:virtual void doSomething(Worker* worker) = 0;};class Worker{public:Worker();void doSomething(){curre...
2018-03-24 21:35:31
234
原创 23种设计模式之访问者模式(行为型,8 Visitor,c++实现)
代码实现:#include <iostream>#include <string>#include "list"using namespace std;class Visitor;class ParkElement{public:virtual void accept(Visitor* visitor) = 0;};class Visitor{public:virtual ...
2018-03-24 18:32:45
173
原创 23种设计模式之备忘录模式(行为型,7 Memento,c++实现)
代码实现:#include <iostream>#include <string>using namespace std;class PersonMemento{public:PersonMemento(string name, int age){this->name = name;this->age = age;}void setName(string nam...
2018-03-18 20:12:00
197
原创 23种设计模式之观察者模式(行为型,6 Observer,c++实现)
代码实现:#include <iostream>#include <string>#include <list>using namespace std;class Secretary;class PlayerObserver{public:PlayerObserver(Secretary* secretary){this->secretary = secr...
2018-03-18 18:13:10
139
原创 23种设计模式之中介者模式(行为型,5 Mediator,c++实现)
代码实现:#include <iostream>#include <string>using namespace std;class Mediator;class Person{public:Person(string name, int sex, int condition, Mediator* mediator){this->name = name;this-&g...
2018-03-18 13:30:02
144
原创 23种设计模式之策略模式(行为型,4 Strategy,c++实现)
代码实现:#include <iostream>using namespace std;class Strategy{public:virtual void crypt() = 0;};class DES : public Strategy{public:virtual void crypt(){cout << "DES crypt" << endl;}};cl...
2018-03-18 12:26:11
132
原创 23种设计模式之责任链模式(行为型,3 Chain of Responsibility,c++实现)
代码实现:#include <iostream>using namespace std;class CarHandler{public:virtual void handleCar() = 0;CarHandler* setNextHandler(CarHandler* handler){this->handler = handler;return handler;}protec...
2018-03-11 17:45:38
133
原创 23种设计模式之命令模式(行为型,2 Command,c++实现)
代码实现:#include <iostream>#include <list>using namespace std;class Doctor{public:void treatEye(){cout << "treat eye" << endl;}void treatNose(){cout << "treat nose" &
2018-03-11 16:23:21
191
原创 23种设计模式之模板方法模式(行为型,1 Template Method,c++实现)
#include <iostream>using namespace std;class MakeCar{public:virtual void makeHead() = 0;virtual void makeBody() = 0;virtual void makeTail() = 0;public:void make(){makeTail();makeBody();makeHead(...
2018-03-11 12:17:40
151
原创 23种设计模式之享元模式(结构型,7 Flyweight,c++实现)
代码实现:#include <iostream>#include <list>#include <string>#include <map>using namespace std;class Person{public:Person(string name, int age){this->name = name;this->age = a...
2018-03-10 20:39:53
170
原创 23种设计模式之外观模式(结构型,6 Facade,c++实现)
代码实现:#include <iostream>#include <list>#include <string>using namespace std;class SubsystemA{public:void doThing(){cout << "SubsystemA do thing" << endl;}};class Subsyste...
2018-03-10 19:20:42
239
原创 23种设计模式之组合模式(结构型,5 Composite,c++实现)
代码实现:#include <iostream>#include <list>#include <string>using namespace std;class IFile{public:virtual void display() = 0;virtual int add(IFile*) = 0;virtual int remove(IFile*) = 0;v...
2018-03-10 17:20:39
186
原创 23种设计模式之桥接模式(结构型,4 Bridge,c++实现)
代码实现:#include <iostream>using namespace std;class Engine{public:virtual void installEngine() = 0;};class Engine4400C : public Engine{public:virtual void installEngine(){cout << "install En...
2018-03-10 16:52:32
181
原创 23种设计模式之适配器模式(结构型,3 Adapter,c++实现)
代码实现:#include <iostream>using namespace std;class Current220v{public:void useCurrent220v(){cout << "use current 220 v" << endl;}};class Current18v{public:virtual void useCurrent18v()...
2018-03-04 17:53:22
161
原创 23种设计模式之装饰器模式(结构型,2 Decorator,c++实现)
代码实现:#include <iostream>using namespace std;class Car{public:virtual void show() = 0;};class RunCar :public Car{public:void show(){cout << "run" << endl;}};class SwimCarDirector :pub...
2018-03-04 17:21:22
169
原创 23种设计模式之代理模式(结构型,1 Proxy,c++实现)
代码实现:#include <iostream>using namespace std;class Bookstore{public:virtual void sale() = 0;};class PhysicalBookstore :public Bookstore{public:void sale(){cout << "sale book" << endl;...
2018-03-04 16:55:56
195
原创 23种设计模式之原型模式(创建型,5 Prototype,c++实现)
代码实现:#define _CRT_SECURE_NO_WARNINGS#include <iostream>#include <string>using namespace std;class Person{public:virtual Person* clone() = 0;virtual void print() = 0;};class CPPProgrammer :...
2018-03-04 12:19:32
158
原创 23种设计模式之建造者模式(创建型,4 Builder,c++实现)
代码实现:#include <iostream>#include <string>using namespace std;class House {public:void setDoor(string door) {this->door = door;}void setWall(string wall) {this->wall = wall;}void setW...
2018-02-27 10:45:57
163
原创 23种设计模式之单例模式(创建型,3 Singleton,c++实现)
1 恶汉式#include <iostream>using namespace std;class Singleton {private:Singleton() {cout << "I am singleton object" << endl;}public:static Singleton* getInstance() {return __singleton;...
2018-02-26 12:49:35
141
原创 23种设计模式之抽象工厂模式(创建型,2 AbstractFactory,c++实现)
#include <stdlib.h>#include <stdio.h>#include <iostream>using namespace std;class Fruit {public:virtual void sayName() = 0;};class SouthBanana :public Fruit {public:void sayName() {c...
2018-02-25 20:04:46
196
原创 23种设计模式之工厂模式(创建型,1 Factory,c++实现)
1 简单工厂模式#include <stdlib.h>#include <stdio.h>#include <iostream>using namespace std;class Fruit {public:virtual void sayName() = 0;};class Banana :public Fruit {public:void sayName()...
2018-02-25 13:39:45
118
原创 23种设计模式介绍
1 创建型模式1.1 工厂模式(Factory)1.2 抽象工厂模式(AbstractFactory)1.3 单例模式(Singleton)1.4 建造者模式(Builder)1.5 原型模式(Prototype)2 结构型模式2.1 桥接模式(Bridge)2.2 适配器模式(Adapter)2.3 装饰器模式(Decorator)2.4 组合模式(Composite)2.5 享元模式(Flyw...
2018-02-25 13:35:10
100
原创 线性顺序表实现(C语言)
1. SeqList.h#ifndef _LINKLIST_H#define _LINKLIST_Htypedef void SeqList;typedef void SeqListNode;SeqList* SeqList_Create(intcapacity);int SeqList_Insert(SeqList*list,Seq
2018-02-04 13:45:32
354
原创 线性链表实现(C语言)
1. LinkList.h#ifndef _LINKLIST_H#define _LINKLIST_Htypedef void LinkList;typedef struct_Tag_LinkListNode {LinkList* next;} LinkListNode;LinkList* LinkList_Create();int Link
2018-01-13 11:42:49
591
原创 Java多线程之线程池submit任务及get返回值流程详解
通过案例分析线程池类Executors相关的ExecutorService的submit方法和Callable的call方法调用流程。有这样一个需求:获取多个任务的返回结果,根据这些任务的返回结果来决定当前线程该做什么。
2017-04-01 23:42:57
6238
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人