diff --git a/SUMMARY.md b/SUMMARY.md index 001a7b9..59f0207 100644 --- a/SUMMARY.md +++ b/SUMMARY.md @@ -48,6 +48,7 @@ * [5.5. Database和数据库打交道](ch5-web/ch5-05-database.md) * [5.6. Ratelimit 服务流量限制](ch5-web/ch5-06-ratelimit.md) * [5.7. Layout大型web项目分层](ch5-web/ch5-07-layout-of-web-project.md) + * [5.8. interface 和 table-driven 开发](ch5-web/ch5-08-interface-and-web.md) * [5.9. 灰度发布和 A/B test](ch5-web/ch5-09-gated-launch.md) * [5.11. Load-balance负载均衡](ch5-web/ch5-11-load-balance.md) * [第六章 分布式系统](ch6-cloud/readme.md) diff --git a/ch5-web/ch5-08-interface-and-web.md b/ch5-web/ch5-08-interface-and-web.md index a519acb..0c5c2c1 100644 --- a/ch5-web/ch5-08-interface-and-web.md +++ b/ch5-web/ch5-08-interface-and-web.md @@ -78,7 +78,7 @@ type OrderCreator interface { 如果我们正在做的是平台系统,需要由平台来定义统一的业务流程和业务规范,那么基于 interface 的抽象就是有意义的。举个例子: -TODO,interface 实现的 uml 图 +![interface-impl](../images/ch6-interface-impl.png) 平台需要服务多条业务线,但数据定义需要统一,所以希望都能走平台定义的流程。作为平台方,我们可以定义一套类似上文的 interface,然后要求接入方的业务必须将这些 interface 都实现。如果 interface 中有其不需要的步骤,那么只要返回 nil,或者忽略就好。 diff --git a/images/ch6-interface-impl.plantuml b/images/ch6-interface-impl.plantuml new file mode 100644 index 0000000..3a80f62 --- /dev/null +++ b/images/ch6-interface-impl.plantuml @@ -0,0 +1,34 @@ +@startuml interface-impl + +interface OrderCreator + +OrderCreator <|-- O2OOrderCreator +OrderCreator <|-- B2BOrderCreator + +interface OrderCreator { + ValidateDistrict() + ValidateVIPProduct() + GetUserInfo() + GetProductDesc() + DecrementStorage() + CreateOrderSnapshot() +} + +class O2OOrderCreator { + ValidateDistrict() + ValidateVIPProduct() + GetUserInfo() + GetProductDesc() + DecrementStorage() + CreateOrderSnapshot() +} + +class B2BOrderCreator { + ValidateDistrict() + ValidateVIPProduct() + GetUserInfo() + GetProductDesc() + DecrementStorage() + CreateOrderSnapshot() +} +@enduml \ No newline at end of file diff --git a/images/ch6-interface-impl.png b/images/ch6-interface-impl.png new file mode 100644 index 0000000..8b3a367 Binary files /dev/null and b/images/ch6-interface-impl.png differ