Skip to content

Commit

Permalink
todo list
Browse files Browse the repository at this point in the history
  • Loading branch information
way2wonder committed Mar 30, 2017
1 parent 7b3492c commit 5f037c0
Show file tree
Hide file tree
Showing 2 changed files with 155 additions and 4 deletions.
6 changes: 6 additions & 0 deletions ToDo_list.md
Original file line number Diff line number Diff line change
@@ -0,0 1,6 @@
## 2017/03/30
1. VIM 学习
[ ] 定制学习计划
[ ] 钦定一本学习书籍

2.
153 changes: 149 additions & 4 deletions java_design_pattern.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 48,6 @@

![Builder](./pictures/multiton.png)


```java
static {
nazguls = new ConcurrentHashMap<>();
Expand All @@ -71,7 70,7 @@
return nazguls.get(name);
}
```

代码中 `getInstance `中用的是map获取对象实例的,而不是用得new,这样的好处就是不用每次都去new一个实例。


Expand All @@ -96,8 95,8 @@

![CallBack 设计模式](./pictures/callback.png)

>jdk中的`CyclicBarrier`
>jdk中的`CyclicBarrier`

## DAO (Data Access Object)
![](./pictures/dao.png)
Expand All @@ -123,3 122,149 @@ JDK IO:






## java 设计模式 进度

1. Architectural
- [x] 5API Gateway
- [x] 5Aggregator Microservices
- [x] 3Event Driven Architecture
- [ ] Hexagonal Architecture
- [x] 4Layers
- [ ] Naked Objects
- [x] 4Service Layer

2. Behavioral (行为设计模式共17)
- [x] 3Vistor (访问者模式) ex: `FileVisitor`
类由多个不同接口的类组成,而你想对于他们执行不同的操作
类组成不变,但是你想搞几个新动作在类的组成上
- [x] 4Template method (模板模式)
- [x] 5Strategy (策略模式)
many related classes differ only in their behavior
你可能需要不同的算法用于权衡取舍时间空间问题
an algorithm uses data that clients shouldn't know about。 隐藏数据
- [x] 3State (状态模式) ex: Mammoth(猛犸愤怒-安静)
- [x] 2Specification also: `Filter Criteria` (过滤器模式)
`Predicate` 和集合的 `Stream`
1.8 `forEach(c -> LOGGER.info(c.toString()))` 新语法
- [x] 3Observer(观察者模式)
- [x] 4Memento (纪念模式) ex: `java.util.Date`
保存一个对象的快照,然后返回到该状态
由以下部分组成
1. MementO接口(空的)
2. Star类中有个Memento接口的内部实现类
3. Star类中有`StarMemento getMemento()`方法
- [x] 2mediator (中介者模式)
定义:用一个中介对象来封装一系列的对象交互,中介者使各对象不需要显式地相互引用,从而使其耦合松散,而且可以独立地改变它们之间的交互。中介者模式又称为调停者模式,它是一种对象行为型模式。
由如下角色构成:
- Mediator: 抽象中介者
- ConcreteMediator: 具体中介者
- Colleague: 抽象同事类
- ConcreteColleague: 具体同事类
- [ ] Iterator (迭代器模式) ex: `java.util.Iterator,java.util.Enumeration`
使用场景:
1. 不暴露内部的结构的情况下访问一个聚合对象的内容
2. 支持多种遍历
3. 提供统一的遍历接口

- [x] 5Delegation (代理模式)
角色(实现统一接口,然后代理类中包含被代理类的引用)
- 代理类
- 被代理类
- [x] 2Dependency Injection(依赖注入 可以扩展很多google的Injector,可以关注下spring的依赖注入)
- `@Inject` 注解(注解的深入理解)
- [x] Command(命令模式)
- Command: 抽象命令类
- ConcreteCommand: 具体命令类
- Invoker: 调用者
- Receiver: 接收者
- Client:客户类
- [ ]
- [ ]
- [ ]
- [ ]
- [ ]
- [ ]
- [ ]
- [ ]
- [ ]
- [ ]
- [ ]



### Visitor
```java
interface Visitor {
void visit(Wheel wheel);
void visit(Engine engine);
void visit(Body body);
void visit(Car car);
}

class Wheel {
private String name;
Wheel(String name) {
this.name = name;
}
String getName() {
return this.name;
}
void accept(Visitor visitor) {
visitor.visit(this);
}
}

class Engine {
void accept(Visitor visitor) {
visitor.visit(this);
}
}

class Body {
void accept(Visitor visitor) {
visitor.visit(this);
}
}

class Car {
private Engine engine = new Engine();
private Body body = new Body();
private Wheel[] wheels
= { new Wheel("front left"), new Wheel("front right"),
new Wheel("back left") , new Wheel("back right") };
void accept(Visitor visitor) {
visitor.visit(this);
engine.accept(visitor);
body.accept(visitor);
for (int i = 0; i < wheels.length; i)
wheels[i].accept(visitor);
}
}

class PrintVisitor implements Visitor {
public void visit(Wheel wheel) {
System.out.println("Visiting " wheel.getName()
" wheel");
}
public void visit(Engine engine) {
System.out.println("Visiting engine");
}
public void visit(Body body) {
System.out.println("Visiting body");
}
public void visit(Car car) {
System.out.println("Visiting car");
}
}

public class VisitorDemo {
static public void main(String[] args) {
Car car = new Car();
Visitor visitor = new PrintVisitor();
car.accept(visitor);
}
}
```

0 comments on commit 5f037c0

Please sign in to comment.