Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
QZero_0
java-design-patterns
提交
1168f6e4
J
java-design-patterns
项目概览
QZero_0
/
java-design-patterns
与 Fork 源项目一致
从无法访问的项目Fork
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
J
java-design-patterns
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
1168f6e4
编写于
8月 31, 2014
作者:
I
Ilkka Seppala
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Updated decorator implementation and class diagram. Added comments.
上级
e760858b
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
22 addition
and
6 deletion
+22
-6
decorator/etc/decorator.jpg
decorator/etc/decorator.jpg
+0
-0
decorator/src/main/java/com/iluwatar/App.java
decorator/src/main/java/com/iluwatar/App.java
+10
-2
decorator/src/main/java/com/iluwatar/Hostile.java
decorator/src/main/java/com/iluwatar/Hostile.java
+8
-0
decorator/src/main/java/com/iluwatar/SmartTroll.java
decorator/src/main/java/com/iluwatar/SmartTroll.java
+3
-3
decorator/src/main/java/com/iluwatar/Troll.java
decorator/src/main/java/com/iluwatar/Troll.java
+1
-1
未找到文件。
decorator/etc/decorator.jpg
查看替换文件 @
e760858b
浏览文件 @
1168f6e4
19.8 KB
|
W:
|
H:
31.8 KB
|
W:
|
H:
2-up
Swipe
Onion skin
decorator/src/main/java/com/iluwatar/App.java
浏览文件 @
1168f6e4
package
com.iluwatar
;
/**
*
* Decorator pattern is more flexible alternative to
* subclassing. The decorator class implements the same
* interface as the target and uses composition to
* "decorate" calls to the target.
*
*/
public
class
App
{
public
static
void
main
(
String
[]
args
)
{
System
.
out
.
println
(
"A simple looking troll approaches."
);
Troll
troll
=
new
Troll
();
Hostile
troll
=
new
Troll
();
troll
.
attack
();
troll
.
fleeBattle
();
System
.
out
.
println
(
"\nA smart looking troll surprises you."
);
Troll
smart
=
new
SmartTroll
(
new
Troll
());
Hostile
smart
=
new
SmartTroll
(
new
Troll
());
smart
.
attack
();
smart
.
fleeBattle
();
}
...
...
decorator/src/main/java/com/iluwatar/Hostile.java
0 → 100644
浏览文件 @
1168f6e4
package
com.iluwatar
;
public
interface
Hostile
{
void
attack
();
void
fleeBattle
();
}
decorator/src/main/java/com/iluwatar/SmartTroll.java
浏览文件 @
1168f6e4
package
com.iluwatar
;
public
class
SmartTroll
extends
Troll
{
public
class
SmartTroll
implements
Hostile
{
private
Troll
decorated
;
private
Hostile
decorated
;
public
SmartTroll
(
Troll
decorated
)
{
public
SmartTroll
(
Hostile
decorated
)
{
this
.
decorated
=
decorated
;
}
...
...
decorator/src/main/java/com/iluwatar/Troll.java
浏览文件 @
1168f6e4
package
com.iluwatar
;
public
class
Troll
{
public
class
Troll
implements
Hostile
{
public
void
attack
()
{
System
.
out
.
println
(
"The troll swings at you with a club!"
);
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录