【发布时间】:2020-07-19 17:32:05
【问题描述】:
我想知道在我的情况下应该使用哪种设计模式:我有 2 个端点,它们使用 2 个服务方法,每个都非常相似,它们的区别仅在于从同一个服务调用一些不同的方法:
我的第一个服务方法(由端点 1 调用):
private Mono<Boolean> deleteAAA(
List<SecuritySet> securitySets, boolean deleteRecoveryPoints) {
return Flux.fromIterable(securitySets)
.flatMap(
protectionSet ->
protectorRepository
...
.flatMap(
protector ->
Mono.zip(
//some code)
.flatMap(
tuple ->
securityCommandService.sendUnprotectedAAA( // -> DIFFERENCE
tuple.getT1()))
.doOnNext(
securitySetId ->
subscriptionResourceService.cancelSubscriptionResources(
securitySet, protector))
.doOnNext(
//some code)
.map(
protectionSetId ->
createSecurityObject(securitySet, protector))
.doOnNext(schedulerService::deleteSecurity)))
.collectList()
.thenReturn(true);
}
第二个端点使用与protectionCommandService.sendUnprotected 不同的非常相似的方法
(deleteBBB)。
我的 secondservice 方法(由端点 2 调用):
private Mono<Boolean> deleteBBB(
List<SecuritySet> securitySets, boolean deleteRecoveryPoints) {
return Flux.fromIterable(securitySets)
.flatMap(
protectionSet ->
protectorRepository
...
.flatMap(
protector ->
Mono.zip(
//some code)
.flatMap(
tuple ->
securityCommandService.sendUnprotectedBBB( // -> DIFFERENCE
tuple.getT1()))
.doOnNext(
securitySetId ->
subscriptionResourceService.cancelSubscriptionResources(
securitySet, protector))
.doOnNext(
//some code)
.map(
protectionSetId ->
createSecurityObject(securitySet, protector))
.doOnNext(schedulerService::deleteSecurity)))
.collectList()
.thenReturn(true);
}
我可以将Type type 之类的参数传递给deleteAAA 和deleteBBB 这些方法,以某种方式区分这些方法的调用。将这两种方法合并为一种方法的最佳方法是什么?
【问题讨论】:
标签: java spring-boot design-patterns spring-webflux