Skip to content

wildcreek/DesignPatterns

Repository files navigation

DesignPatterns

一句话举例设计模式


Java design patterns for learning ,described briefly with daily life example.

Strategy 策略模式

渔夫有三种捕鱼策略:钓鱼、网捕、叉鱼

A fisherman could catch fish with three strategies : fishing with rod ,seine or spear.

Observer 观察者模式

铃声响了,老师听到了,走向教室;学生听到了,收起杂物准备上课

With bell ringing ,the teacher headed for classroom ,the students prepared for class.

Decorator 装饰器模式

有一个松木圣诞树,我们既可以装饰糖果,也可以装饰小灯泡

There is a pine Christmas tree, we could decorate it with candies ,thus making it a candy christmas tree ,or we could decorate with lights.

Singleton 单例模式

饿汉式占用资源;懒汉式用双检锁+volatile ,或者放在私有静态内部类的静态成员变量中。

Tree ways to achieve singleton ,eager way consumes resources in advance ; lazy ways use either volatile and double check locking ,or static inner class and store the instance in its static variable.

Adapter 适配器模式

启动电视盒子,要先连接上专用电源,电源具备适配器的功能,接入插座,将插座的交流电转换为直流电。

A working tv box needed to plug in some certain type power device , the power device connecting to the pow outlet acts as an adapter ,transforming alternating current to direct current.

About

一句话设计模式

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages