Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
QZero_0
java-design-patterns
提交
e742950c
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,发现更多精彩内容 >>
提交
e742950c
编写于
8月 13, 2014
作者:
I
Ilkka Seppala
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
added decorator sample
上级
1d4f0f1e
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
78 addition
and
0 deletion
+78
-0
decorator/pom.xml
decorator/pom.xml
+23
-0
decorator/src/main/java/com/iluwatar/App.java
decorator/src/main/java/com/iluwatar/App.java
+18
-0
decorator/src/main/java/com/iluwatar/SmartTroll.java
decorator/src/main/java/com/iluwatar/SmartTroll.java
+23
-0
decorator/src/main/java/com/iluwatar/Troll.java
decorator/src/main/java/com/iluwatar/Troll.java
+13
-0
pom.xml
pom.xml
+1
-0
未找到文件。
decorator/pom.xml
0 → 100644
浏览文件 @
e742950c
<?xml version="1.0"?>
<project
xsi:schemaLocation=
"http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
xmlns=
"http://maven.apache.org/POM/4.0.0"
xmlns:xsi=
"http://www.w3.org/2001/XMLSchema-instance"
>
<modelVersion>
4.0.0
</modelVersion>
<parent>
<groupId>
com.iluwatar
</groupId>
<artifactId>
java-design-patterns
</artifactId>
<version>
1.0-SNAPSHOT
</version>
</parent>
<groupId>
com.iluwatar
</groupId>
<artifactId>
decorator
</artifactId>
<version>
1.0-SNAPSHOT
</version>
<name>
decorator
</name>
<url>
http://maven.apache.org
</url>
<dependencies>
<dependency>
<groupId>
junit
</groupId>
<artifactId>
junit
</artifactId>
<version>
3.8.1
</version>
<scope>
test
</scope>
</dependency>
</dependencies>
</project>
decorator/src/main/java/com/iluwatar/App.java
0 → 100644
浏览文件 @
e742950c
package
com.iluwatar
;
public
class
App
{
public
static
void
main
(
String
[]
args
)
{
System
.
out
.
println
(
"A simple looking troll approaches."
);
Troll
troll
=
new
Troll
();
troll
.
attack
();
troll
.
fleeBattle
();
System
.
out
.
println
(
"\nA smart looking troll surprises you."
);
Troll
smart
=
new
SmartTroll
(
new
Troll
());
smart
.
attack
();
smart
.
fleeBattle
();
}
}
decorator/src/main/java/com/iluwatar/SmartTroll.java
0 → 100644
浏览文件 @
e742950c
package
com.iluwatar
;
public
class
SmartTroll
extends
Troll
{
private
Troll
decorated
;
public
SmartTroll
(
Troll
decorated
)
{
this
.
decorated
=
decorated
;
}
@Override
public
void
attack
()
{
System
.
out
.
println
(
"The troll throws a rock at you!"
);
decorated
.
attack
();
}
@Override
public
void
fleeBattle
()
{
System
.
out
.
println
(
"The troll calls for help!"
);
decorated
.
fleeBattle
();
}
}
decorator/src/main/java/com/iluwatar/Troll.java
0 → 100644
浏览文件 @
e742950c
package
com.iluwatar
;
public
class
Troll
{
public
void
attack
()
{
System
.
out
.
println
(
"The troll swings at you with a club!"
);
}
public
void
fleeBattle
()
{
System
.
out
.
println
(
"The troll shrieks in horror and runs away!"
);
}
}
pom.xml
浏览文件 @
e742950c
...
...
@@ -26,5 +26,6 @@
<module>
adapter
</module>
<module>
bridge
</module>
<module>
composite
</module>
<module>
decorator
</module>
</modules>
</project>
\ No newline at end of file
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录