Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
无难事者若执
23种设计模式
提交
aaa05319
23种设计模式
项目概览
无难事者若执
/
23种设计模式
与 Fork 源项目一致
Fork自
inscode / Java
通知
1
Star
1
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
23种设计模式
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
提交
aaa05319
编写于
10月 16, 2023
作者:
E
ex_kongxiang
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
feat(桥接模式):新增
上级
60c0e777
变更
21
隐藏空白更改
内联
并排
Showing
21 changed file
with
417 addition
and
20 deletion
+417
-20
.gitignore
.gitignore
+5
-0
java/.gitignore
java/.gitignore
+2
-0
java/com/kongxiang/raindrop/dp/type/structure/bridge/AbstractDiscount.java
...g/raindrop/dp/type/structure/bridge/AbstractDiscount.java
+18
-0
java/com/kongxiang/raindrop/dp/type/structure/bridge/Client.java
...m/kongxiang/raindrop/dp/type/structure/bridge/Client.java
+32
-0
java/com/kongxiang/raindrop/dp/type/structure/bridge/Discount.java
...kongxiang/raindrop/dp/type/structure/bridge/Discount.java
+18
-0
java/com/kongxiang/raindrop/dp/type/structure/bridge/FiveDisCount.java
...xiang/raindrop/dp/type/structure/bridge/FiveDisCount.java
+26
-0
java/com/kongxiang/raindrop/dp/type/structure/bridge/NoDisCount.java
...ngxiang/raindrop/dp/type/structure/bridge/NoDisCount.java
+28
-0
java/com/kongxiang/raindrop/dp/type/structure/bridge/PriceRange.java
...ngxiang/raindrop/dp/type/structure/bridge/PriceRange.java
+23
-0
java/com/kongxiang/raindrop/dp/type/structure/bridge/PriceRange1000.java
...ang/raindrop/dp/type/structure/bridge/PriceRange1000.java
+21
-0
java/com/kongxiang/raindrop/dp/type/structure/bridge/PriceRange1000To5000.java
...indrop/dp/type/structure/bridge/PriceRange1000To5000.java
+21
-0
java/com/kongxiang/raindrop/dp/type/structure/bridge/PriceRange5000.java
...ang/raindrop/dp/type/structure/bridge/PriceRange5000.java
+21
-0
java/com/kongxiang/raindrop/dp/type/structure/bridge/twodimensional/Point.java
...indrop/dp/type/structure/bridge/twodimensional/Point.java
+17
-0
java/com/kongxiang/raindrop/dp/type/structure/bridge/twodimensional/Student.java
...drop/dp/type/structure/bridge/twodimensional/Student.java
+46
-0
java/com/kongxiang/raindrop/dp/type/structure/bridge/twodimensional/X.java
...g/raindrop/dp/type/structure/bridge/twodimensional/X.java
+18
-0
java/com/kongxiang/raindrop/dp/type/structure/bridge/twodimensional/XAdd1.java
...indrop/dp/type/structure/bridge/twodimensional/XAdd1.java
+20
-0
java/com/kongxiang/raindrop/dp/type/structure/bridge/twodimensional/XMov2.java
...indrop/dp/type/structure/bridge/twodimensional/XMov2.java
+20
-0
java/com/kongxiang/raindrop/dp/type/structure/bridge/twodimensional/Y.java
...g/raindrop/dp/type/structure/bridge/twodimensional/Y.java
+34
-0
java/com/kongxiang/raindrop/dp/type/structure/bridge/twodimensional/Y2x.java
...raindrop/dp/type/structure/bridge/twodimensional/Y2x.java
+24
-0
java/com/kongxiang/raindrop/dp/type/structure/bridge/twodimensional/Ylog.java
...aindrop/dp/type/structure/bridge/twodimensional/Ylog.java
+23
-0
main.iml
main.iml
+0
-6
myartifactid.iml
myartifactid.iml
+0
-14
未找到文件。
.gitignore
0 → 100644
浏览文件 @
aaa05319
*.class
*.iml
.idea
out/
target/
\ No newline at end of file
java/.gitignore
0 → 100644
浏览文件 @
aaa05319
*.class
*.iml
java/com/kongxiang/raindrop/dp/type/structure/bridge/AbstractDiscount.java
0 → 100644
浏览文件 @
aaa05319
package
com.kongxiang.raindrop.dp.type.structure.bridge
;
/**
* @author 孔翔
* @since 2023-10-16
* copyright for author : 孔翔 at 2023-10-16
* dp
*/
public
abstract
class
AbstractDiscount
implements
Discount
{
protected
PriceRange
priceRange
;
public
AbstractDiscount
(
PriceRange
priceRange
)
{
this
.
priceRange
=
priceRange
;
}
}
java/com/kongxiang/raindrop/dp/type/structure/bridge/Client.java
0 → 100644
浏览文件 @
aaa05319
package
com.kongxiang.raindrop.dp.type.structure.bridge
;
/**
* @author 孔翔
* @since 2023-10-16
* copyright for author : 孔翔 at 2023-10-16
* dp
*/
public
class
Client
{
public
static
void
main
(
String
[]
args
)
{
double
totalMoney
=
10000.0
;
// 实现了 6种 实现
AbstractDiscount
d1
=
new
FiveDisCount
(
new
PriceRange1000
());
AbstractDiscount
d2
=
new
FiveDisCount
(
new
PriceRange1000To5000
());
AbstractDiscount
d3
=
new
FiveDisCount
(
new
PriceRange5000
());
AbstractDiscount
d4
=
new
NoDisCount
(
new
PriceRange1000
());
AbstractDiscount
d5
=
new
NoDisCount
(
new
PriceRange1000To5000
());
AbstractDiscount
d6
=
new
NoDisCount
(
new
PriceRange5000
());
d1
.
calculatePrice
(
totalMoney
);
d2
.
calculatePrice
(
totalMoney
);
d3
.
calculatePrice
(
totalMoney
);
d4
.
calculatePrice
(
totalMoney
);
d5
.
calculatePrice
(
totalMoney
);
d6
.
calculatePrice
(
totalMoney
);
}
}
java/com/kongxiang/raindrop/dp/type/structure/bridge/Discount.java
0 → 100644
浏览文件 @
aaa05319
package
com.kongxiang.raindrop.dp.type.structure.bridge
;
/**
* 折扣维度
* @author 孔翔
* @since 2023-10-16
* copyright for author : 孔翔 at 2023-10-16
* dp
*/
public
interface
Discount
{
/**
* 计算折扣价
* @param totalMoney 总价
* @return 打折后的价格
*/
public
double
calculatePrice
(
double
totalMoney
);
}
java/com/kongxiang/raindrop/dp/type/structure/bridge/FiveDisCount.java
0 → 100644
浏览文件 @
aaa05319
package
com.kongxiang.raindrop.dp.type.structure.bridge
;
/**
* @author 孔翔
* @since 2023-10-16
* copyright for author : 孔翔 at 2023-10-16
* dp
*/
public
class
FiveDisCount
extends
AbstractDiscount
{
public
FiveDisCount
(
PriceRange
priceRange
)
{
super
(
priceRange
);
}
@Override
public
double
calculatePrice
(
double
totalMoney
)
{
boolean
inRange
=
super
.
priceRange
.
isInRange
(
totalMoney
);
if
(
inRange
){
totalMoney
=
totalMoney
-
super
.
priceRange
.
returnCase
();
System
.
out
.
println
(
"符合售价区间返现规则:返现价格"
+
super
.
priceRange
.
returnCase
()
+
"返现后价格 :"
+
totalMoney
);
}
else
{
System
.
out
.
println
(
"不符合返现规则:价格"
+
totalMoney
);
}
System
.
out
.
println
(
"计算价格 :"
+
totalMoney
+
" x 折扣"
+
0.5
+
" = "
+
(
totalMoney
*
0.5
));
return
(
totalMoney
*
0.5
);
}
}
java/com/kongxiang/raindrop/dp/type/structure/bridge/NoDisCount.java
0 → 100644
浏览文件 @
aaa05319
package
com.kongxiang.raindrop.dp.type.structure.bridge
;
/**
* 不打折
*
* @author 孔翔
* @since 2023-10-16
* copyright for author : 孔翔 at 2023-10-16
* dp
*/
public
class
NoDisCount
extends
AbstractDiscount
{
public
NoDisCount
(
PriceRange
priceRange
)
{
super
(
priceRange
);
}
@Override
public
double
calculatePrice
(
double
totalMoney
)
{
boolean
inRange
=
super
.
priceRange
.
isInRange
(
totalMoney
);
if
(
inRange
)
{
totalMoney
=
totalMoney
-
super
.
priceRange
.
returnCase
();
System
.
out
.
println
(
"符合售价区间返现规则:返现价格"
+
super
.
priceRange
.
returnCase
()
+
"返现后价格 :"
+
totalMoney
);
}
else
{
System
.
out
.
println
(
"不符合返现规则:价格"
+
totalMoney
);
}
System
.
out
.
println
(
"计算价格 :"
+
totalMoney
+
" x 折扣"
+
1
+
" = "
+
(
totalMoney
*
1
));
return
(
totalMoney
*
1
);
}
}
java/com/kongxiang/raindrop/dp/type/structure/bridge/PriceRange.java
0 → 100644
浏览文件 @
aaa05319
package
com.kongxiang.raindrop.dp.type.structure.bridge
;
/**
* 售价区间
* @author 孔翔
* @since 2023-10-16
* copyright for author : 孔翔 at 2023-10-16
* dp
*/
public
interface
PriceRange
{
/**
* 判断是否是当前区间
* @param price 商品售价
* @return 所属区间
*/
public
boolean
isInRange
(
double
price
);
/**
* 根据区间返现
* @return 返现额度
*/
public
double
returnCase
();
}
java/com/kongxiang/raindrop/dp/type/structure/bridge/PriceRange1000.java
0 → 100644
浏览文件 @
aaa05319
package
com.kongxiang.raindrop.dp.type.structure.bridge
;
/**
* @author 孔翔
* @since 2023-10-16
* copyright for author : 孔翔 at 2023-10-16
* dp
*/
public
class
PriceRange1000
implements
PriceRange
{
@Override
public
boolean
isInRange
(
double
price
)
{
return
price
<
1000
;
}
@Override
public
double
returnCase
()
{
return
5
;
}
}
java/com/kongxiang/raindrop/dp/type/structure/bridge/PriceRange1000To5000.java
0 → 100644
浏览文件 @
aaa05319
package
com.kongxiang.raindrop.dp.type.structure.bridge
;
/**
* @author 孔翔
* @since 2023-10-16
* copyright for author : 孔翔 at 2023-10-16
* dp
*/
public
class
PriceRange1000To5000
implements
PriceRange
{
@Override
public
boolean
isInRange
(
double
price
)
{
return
price
>
1000
&&
price
<
5000
;
}
@Override
public
double
returnCase
()
{
return
100
;
}
}
java/com/kongxiang/raindrop/dp/type/structure/bridge/PriceRange5000.java
0 → 100644
浏览文件 @
aaa05319
package
com.kongxiang.raindrop.dp.type.structure.bridge
;
/**
* @author 孔翔
* @since 2023-10-16
* copyright for author : 孔翔 at 2023-10-16
* dp
*/
public
class
PriceRange5000
implements
PriceRange
{
@Override
public
boolean
isInRange
(
double
price
)
{
return
price
>
5000
;
}
@Override
public
double
returnCase
()
{
return
500
;
}
}
java/com/kongxiang/raindrop/dp/type/structure/bridge/twodimensional/Point.java
0 → 100644
浏览文件 @
aaa05319
package
com.kongxiang.raindrop.dp.type.structure.bridge.twodimensional
;
import
lombok.AllArgsConstructor
;
import
lombok.Data
;
/**
* @author 孔翔
* @since 2023-10-16
* copyright for author : 孔翔 at 2023-10-16
* dp
*/
@Data
@AllArgsConstructor
public
class
Point
{
private
int
x
;
private
int
y
;
}
java/com/kongxiang/raindrop/dp/type/structure/bridge/twodimensional/Student.java
0 → 100644
浏览文件 @
aaa05319
package
com.kongxiang.raindrop.dp.type.structure.bridge.twodimensional
;
import
com.kongxiang.raindrop.dp.type.structure.bridge.twodimensional.XAdd1
;
import
com.kongxiang.raindrop.dp.type.structure.bridge.twodimensional.Y
;
import
com.kongxiang.raindrop.dp.type.structure.bridge.twodimensional.Y2x
;
import
lombok.extern.slf4j.Slf4j
;
/**
* @author 孔翔
* @since 2023-10-16
* copyright for author : 孔翔 at 2023-10-16
* dp
*/
public
class
Student
{
public
static
void
main
(
String
[]
args
)
{
// 练习题
// 创建试卷练习题
//试题: 偏移函数 dx+1 ,y函数 x*2 ,当给定x轴上的点是8的时候,求空间上的点
Y
exercise
=
new
Y2x
(
new
XAdd1
());
answerQuest
(
exercise
);
exercise
=
new
Y2x
(
new
XMov2
());
answerQuest
(
exercise
);
exercise
=
new
Ylog
(
new
XMov2
());
answerQuest
(
exercise
);
exercise
=
new
Ylog
(
new
XAdd1
());
answerQuest
(
exercise
);
// 假设 x 有 m种扩展算法, y种有n种算法
// 现在将2维拓展到3维,新增一个维度的化,每增加一个三维z的抽象实例
// 就可以新增 mxn 的不同算法题。
// 如果z 有 o 种算法。那么 在三维空间种的算法表达就有 m x n x o 种 具体算法题。
//Z exercise = new Zlog(new Ylog(new XAdd1()));
}
private
static
void
answerQuest
(
Y
exercise
)
{
Point
fxResult
=
exercise
.
getFxResult
(
8
);
System
.
out
.
println
(
"x "
+
fxResult
.
getX
()
+
" : Y "
+
fxResult
.
getY
());
}
}
java/com/kongxiang/raindrop/dp/type/structure/bridge/twodimensional/X.java
0 → 100644
浏览文件 @
aaa05319
package
com.kongxiang.raindrop.dp.type.structure.bridge.twodimensional
;
/**
* @author 孔翔
* @since 2023-10-16
* copyright for author : 孔翔 at 2023-10-16
* dp
*/
public
interface
X
{
/**
* x轴函数
* @param dx
* @return
*/
int
offsetFun
(
int
dx
);
}
java/com/kongxiang/raindrop/dp/type/structure/bridge/twodimensional/XAdd1.java
0 → 100644
浏览文件 @
aaa05319
package
com.kongxiang.raindrop.dp.type.structure.bridge.twodimensional
;
/**
* @author 孔翔
* @since 2023-10-16
* copyright for author : 孔翔 at 2023-10-16
* dp
*/
public
class
XAdd1
implements
X
{
/**
* x坐标偏移函数
* f(dx)=dx+1
* @param dx
* @return
*/
@Override
public
int
offsetFun
(
int
dx
)
{
return
dx
+
1
;
}
}
java/com/kongxiang/raindrop/dp/type/structure/bridge/twodimensional/XMov2.java
0 → 100644
浏览文件 @
aaa05319
package
com.kongxiang.raindrop.dp.type.structure.bridge.twodimensional
;
/**
* @author 孔翔
* @since 2023-10-16
* copyright for author : 孔翔 at 2023-10-16
* dp
*/
public
class
XMov2
implements
X
{
/**
* x坐标偏移函数
* f(dx)=dx/2
* @param dx
* @return
*/
@Override
public
int
offsetFun
(
int
dx
)
{
return
dx
/
2
;
}
}
java/com/kongxiang/raindrop/dp/type/structure/bridge/twodimensional/Y.java
0 → 100644
浏览文件 @
aaa05319
package
com.kongxiang.raindrop.dp.type.structure.bridge.twodimensional
;
/**
* @author 孔翔
* @since 2023-10-16
* copyright for author : 孔翔 at 2023-10-16
* dp
*/
public
abstract
class
Y
{
private
X
fdx
;
public
Y
(
X
x
){
this
.
fdx
=
x
;
}
private
int
calcuY
(
int
dx
)
{
int
realX
=
fdx
.
offsetFun
(
dx
);
return
fx
(
realX
);
}
public
Point
getFxResult
(
int
x
){
return
new
Point
(
fdx
.
offsetFun
(
x
),
calcuY
(
x
));
}
/**
* 计算 y=f(x) 的 函数
* @param realX 实际坐标值
* @return 实际y轴坐标
*/
protected
abstract
int
fx
(
int
realX
);
}
java/com/kongxiang/raindrop/dp/type/structure/bridge/twodimensional/Y2x.java
0 → 100644
浏览文件 @
aaa05319
package
com.kongxiang.raindrop.dp.type.structure.bridge.twodimensional
;
/**
* @author 孔翔
* @since 2023-10-16
* copyright for author : 孔翔 at 2023-10-16
* dp
*/
public
class
Y2x
extends
Y
{
public
Y2x
(
X
x
)
{
super
(
x
);
}
/**
* f(x) = 2 * x
* @param realX 实际坐标值
* @return
*/
@Override
protected
int
fx
(
int
realX
)
{
return
realX
*
2
;
}
}
java/com/kongxiang/raindrop/dp/type/structure/bridge/twodimensional/Ylog.java
0 → 100644
浏览文件 @
aaa05319
package
com.kongxiang.raindrop.dp.type.structure.bridge.twodimensional
;
/**
* @author 孔翔
* @since 2023-10-16
* copyright for author : 孔翔 at 2023-10-16
* dp
*/
public
class
Ylog
extends
Y
{
public
Ylog
(
X
x
)
{
super
(
x
);
}
/**
* f(x)=log(x)
* @param realX 实际坐标值
* @return
*/
@Override
protected
int
fx
(
int
realX
)
{
return
(
int
)
Math
.
log
(
realX
*
1.0
);
}
}
main.iml
已删除
100644 → 0
浏览文件 @
60c0e777
<?xml version="1.0" encoding="UTF-8"?>
<module
version=
"4"
>
<component
name=
"SonarLintModuleSettings"
>
<option
name=
"uniqueId"
value=
"c0754f24-9258-4617-85c1-cf884e30c2e1"
/>
</component>
</module>
\ No newline at end of file
myartifactid.iml
已删除
100644 → 0
浏览文件 @
60c0e777
<?xml version="1.0" encoding="UTF-8"?>
<module
version=
"4"
>
<component
name=
"AdditionalModuleElements"
>
<content
url=
"file://$MODULE_DIR$/.."
>
<sourceFolder
url=
"file://$MODULE_DIR$"
isTestSource=
"false"
/>
<sourceFolder
url=
"file://$MODULE_DIR$/java"
isTestSource=
"false"
/>
<sourceFolder
url=
"file://$MODULE_DIR$/../test"
isTestSource=
"true"
/>
<sourceFolder
url=
"file://$MODULE_DIR$/../test/java"
isTestSource=
"false"
/>
</content>
</component>
<component
name=
"SonarLintModuleSettings"
>
<option
name=
"uniqueId"
value=
"963d936e-8979-414a-98ac-724c2c4fc949"
/>
</component>
</module>
\ No newline at end of file
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录