04. 懒惰与隔阂
复杂性的来源
复杂性不是凭空而来,很多时候也不是刻意为之,这也就意味着复杂性的增加往往不会以我们的主观意志为转移。就像房间里的大象,我们无法逃避,也不能视而不见,本节即来讨论复杂性的主要来源点可能有哪些。
交互且无扩展性设计
当吸积效应导致的大规模系统,结合了交互这个特性,会使技术系统更加复杂。一个技术系统除了作用于自身,还会与其它大量系统产生交互。比如下单购买一件商品,那么订单系统,商品系统,支付系统,物流系统,卡券系统就会交互协作。这样吸积的复杂性,由于交互特性的出现,会呈现几何级数上升。交互带来两种特性:第一是互操作性。在搜索引擎上查询去某地怎么走,搜索引擎会告诉你打车需要多长时间,并提供一个打车按钮。第二是相互依赖性。比如下订单时需要使用优惠券,那么当卡券系统出现问题时就会影响订单系统。
对于只有一个业务的简单场景,并不需要扩展,问题也不突出,这也是为什么这个点经常被忽略的原因,因为我们大部分的系统都是从单一业务开始的。但是随着支持的业务越来越多,代码里面开始出现大量的
不合理的业务封装
不合理的业务封装是一个相对宽泛的概念,其具体的表现譬如面向过程而不是对象、分层不合理等。面向对象不仅是一个语言,更是一种思维方式,但是很多时候我们更会用事务脚本的方式,面向过程地来编写代码。譬如
另一个不合理的业务封装,就是不合理的分层;俗话说,计算机科学领域的任何问题都可以通过增加一个间接的中间层来解决。分层最大的好处就是分离关注点,让每一层只解决该层关注的问题,从而将复杂的问题简化,起到分而治之的作用。但是,并非分层越多越好,过多的层次不仅不能带来好处,反而会增加系统的复杂性和降低系统性能。分层太多和没有分层都会导致系统复杂度的上升,因此我们的原则是不可以没有分层,但是只分有必要的层。
缺乏统一语言
典型的敏捷开发的结构,流水线上的各个角色往往会专注于自己负责的环节,精细化的分工也限制了每个角色的全局视角;虽然我们经常提倡所谓的主人翁意识,但是在落地时又很难去推进。

Model‐Driven Design is the process of binding an analysis model to a code implementation model, ensuring that both stay in sync and are useful during evolution.Model‐Driven Design differs from DDD in that it is focused on implementation and any constraints that may require changes to an initial model, whereas DDD focuses on language, collaboration, and domain knowledge.
Historically, the capturing of requirements for software systems was seen as an activity that could occur long before coding was due to start. Business experts would talk to business analysts, who in turn would talk to architects, who would produce an analysis model based on all the information from the problem domain. This analysis model would then be handed over to the developers, along with wireframes and work flow diagrams, so they could build the system.
As developers start to implement the analysis model in code, they often find a mismatch between the high‐level artifacts produced by architects and the reality of building the system. However, at this stage there is often no feedback loop for developers to talk to the business and architects, so the analysis model can be updated and their input enacted. Instead, the developers diverge from the analysis model, and their implementation often overlooks important and descriptive domain terms and concepts that would have provided deeper insight and understanding of the domain.
As the development team further evolves away from the analysis model, it becomes less and less useful. Crucial insight into the model is lost as the development team focuses on abstracting technical concerns instead of business concepts. In the end the job gets done, but the code bears no reflection to the original analysis model. The business still believes the original analysis models are correct and is unaware of the alterations within the code model.
事先设计(Upfront Design)的弊端在于,随着业务的变化,因为领域专家与技术人员有不同的模型理解,代码库会变得失去控制:

缺乏约束与规范
在团队协作开发的背景下,缺少规范和约束会严重损害架构的一致性(Consistency
最好的约束就是在架构层面,通过