有什么软件架构属于单体架构

From time to time someone mentions this term. In the most diverse contexts. It’s a term that has been used to express many different things, and when a word can mean anything, it ends up meaning nothing. In this article I explain my own vision, after a lot of study, about what software architecture actually is, in the most precise way I could until now.

有时会有人提到这个词。 在最多样化的环境中。 这是一个用来表达许多不同事物的术语,当一个单词可以表达任何含义时,它最终没有任何意义。 在这篇文章中,我经过大量研究后以迄今为止最精确的方式解释了我对软件体系结构的看法。

Also available in Portuguese

也提供葡萄牙语

As software crafters, we write code to the best of our ability, according to the knowledge we currently have about programming and also about the application’s business domain.

作为软件设计者,我们将根据我们目前对编程以及应用程序业务领域的知识,尽力而为地编写代码。

As time goes by, we learn more and more, not only about programming techniques but also about the peculiarities and characteristics of the business domain.

随着时间的流逝,我们不仅学到了编程技术,而且学到了业务领域的特殊性和特征,而且学到了越来越多的东西。

Trends change, new programming techniques are created and some of them get more traction in the market. The business domain also evolves and changes as more features are added to the software.

趋势在变化,新的编程技术不断涌现,其中一些在市场上越来越受关注。 随着更多功能添加到软件中,业务领域也不断发展和变化。

So, the code we have written seems to slowly decay, because we wrote it without the new knowledge we now have. Every time we look at the older code, more certain we become that it doesn’t reflect anymore the best modeling for the problem it should solve.

因此,我们编写的代码似乎正在慢慢衰减,因为我们在编写时没有掌握新知识。 每次查看较旧的代码时,我们都会更加确信它不再反映出应该解决的最佳建模方法。

Code decaying over time 代码随时间衰减

This is normal. It happens since the beginning of a project and it will keep happening until the end. Software is soft because it was made to be changed. Refactored. Experimented. Adjusted. Corrected. Incremented.

这是正常的。 它从项目开始就发生,并将一直持续到结束。 软件之所以软,是因为它被更改了。 重构。 实验过 已调整。 已更正。 递增。

But changing this code isn’t something simple, because systems are, most of the time, complex. The impact of a change isn’t always clear. We get struck by that fear of breaking something. And that’s why we write automated testes. To be able to fearlessly change software. To be able to rewrite, adjust, experiment, fix.

但是更改此代码并非易事,因为在大多数情况下,系统很复杂。 变更的影响并不总是很清楚。 我们害怕破坏某些东西而感到震惊。 这就是我们编写自动化睾丸的原因。 能够无所畏惧地更改软件。 为了能够重写,调整,试验,修复。

Automated tests to measure the impact of change

自动化测试以衡量变化的影响

It’s not only to know if the software works. If we would never change that system, a well-done manual test would be pretty good at making sure a version works. Perhaps it would even be better then automated tests, because manual tests are forcefully end-to-end and also catch unforeseen issues in UX and business domain.

不仅要知道软件是否有效。 如果我们永远都不会更改该系统,那么经过良好的手动测试将非常擅长于确保版本正常运行。 也许比自动测试更好,因为手动测试是强制性的端到端,并且还可以捕获UX和业务领域中无法预料的问题。

It turns out that writing automated tests isn’t enough to make our software easy to change. If the code gets too coupled to implementation details like UI, database and communication with other systems, any change in code is subject to the intrinsic modeling that these external factors impose on our code.

事实证明,编写自动化测试不足以使我们的软件易于更改。 如果代码与实现细节(如UI,数据库以及与其他系统的通信)过于耦合,则代码的任何更改都将受到这些外部因素强加给我们代码的固有建模的约束。

Any change in the way business rules are modeled imposes changes in multiple automated tests and in the implementation details. To improve the name of a variable inside a business rule is to impose that it changes also in the database, or the screen, or in other places. Bigger changes, structural ones, chill down our spine.

对业务规则建模方式的任何更改都将在多个自动化测试和实施详细信息中进行更改。 要改善业务规则中变量的名称,就是要使其在数据库,屏幕或其他位置也进行更改。 较大的变化,结构性变化会放松我们的脊柱。

When one change causes others

当一种变化导致其他变化时

That’s why architectures were created. Architecture isn’t a recipe to follow when modeling a system. It isn’t a nomenclature. It isn’t a way to organize business rules into classes or methods. Architecture isn’t DDD[1].

这就是创建架构的原因。 在对系统进行建模时,架构并不是要遵循的秘诀。 这不是术语。 这不是将业务规则组织到类或方法中的方法。 架构不是DDD [1]。

Architectures are ways to isolate our code from external factors, so we have the freedom to model and remodel the solution to a problem in the way we understand to be the best at the moment. And then remodel it again. And again.

架构是将我们的代码与外部因素隔离的方法,因此我们可以自由地以我们目前认为最好的方式对问题的解决方案进行建模和重新建模。 然后再次进行重塑。 然后再次。

One of the most famous architectures today is the Clean Architecture:

当今最著名的体系结构之一是Clean Architecture :

什么事单体架构项目_python

In the article, Uncle Bob seems to provide really the recipe, the nomenclature and the way to organize business rules into classes and methods. But if you read carefully, you’ll notice that the objective — of all architectures — is to achieve the so called independence, the so called freedom.

在本文中,鲍勃叔叔似乎确实提供了配方,术语以及将业务规则组织到类和方法中的方法。 但是,如果仔细阅读,您会注意到,所有体系结构的目标都是实现所谓的独立性,即所谓的自由。

Freedom to learn and remodel the system without breaking everything. Freedom to clean the code.

自由学习和改造系统而不会破坏一切。 自由清理代码。

That’s why there are Usecases (Interactors). They represent the actions users can do in the system. They are the communication bridge between the UI and the application. And that’s also why there are Presenters, which make the way back from the application to the UI when there’s some extra processing involved to present that information. They are part of the shell, they can be named differently and have other forms, as long as they fulfill their role of isolating.

这就是为什么存在用例(交互器)的原因。 它们代表用户可以在系统中执行的操作。 它们是UI和应用程序之间的通信桥梁。 这就是为什么有Presenters的原因,当涉及到一些额外的处理来呈现信息时,Presenter会从应用程序返回到UI。 它们是外壳的一部分,它们可以不同地命名,也可以具有其他形式,只要它们能够发挥其隔离作用即可。

From there inwards, rigid rules shouldn’t be imposed. That’s the point. Freedom from the imposed rules. All the tests we have written, all the Usecases and Presenters, exist so we have greater freedom to define how our Entities are and how they’re going to behave.

从那里开始,不应强加严格的规则。 这才是重点。 不受规定的约束。 我们编写的所有测试,所有用例和演示者都存在,因此我们拥有更大的自由来定义实体的方式以及实体的行为方式。

什么事单体架构项目_linux_02

Once the library’s architecture is ready, we can organize the books as we please 图书馆的架构准备就绪后,我们可以根据需要组织书籍

So we ourselves can define if they should be functions, classes, how many method they ought to have. If they will be instantiated in the Gateways (Repositories), if they’ll receive data in the constructor or in the methods. And any other way of modeling.

因此,我们自己可以定义它们是否应该是函数,类,应该具有多少种方法。 如果它们将在网关(存储库)中实例化,则它们将在构造函数或方法中接收数据。 以及任何其他建模方式。

Each domain has its peculiarities. The rules don’t fit, principles do. Each principle is going to be applied in a given way in each domain. It all depends. But to advance at this point we need to get used to thinking again. Maybe go back and do a few katas or dojos.

每个域都有其特殊性。 规则不适合,原则适合。 每种原理都将以给定的方式应用于每个领域。 一切取决于。 但是要在这一点上取得进步,我们需要习惯于重新思考。 也许回去做几片kata或dojos。

Forget the rules, forget the patterns… What’s the simplest way to solve a problem?

忘记规则,忘记模式……解决问题的最简单方法是什么?

Forget the screen, forget the database… What’s the simplest algorithm to solve that college challenge given by the professor?

忘记屏幕,忘记数据库...解决教授提出的大学挑战的最简单算法是什么?

Forget the Usecase, forget the architecture… Write a test, see it failing, write the minimum code possible to make it pass, and then refactor.

忘记用例,忘记体系结构…编写测试,查看失败,编写可能通过的最少代码,然后进行重构。

Forget the class, forget the interface… What is more readable? What is simpler to understand to the rookie that just started at the company?

忘了上课,忘了界面...更具可读性的是什么? 对于刚开始在公司工作的新手来说,最容易理解的是什么?

Forget the pattern, forget the inheritance… Is the package where I put this code coherent? Is it easy to anyone using this rule to find it?

忘记模式,忘记继承...我放置此代码的软件包是否一致? 使用此规则的任何人都容易找到它吗?

Of course we’ll be making use of the UI, the database, of Usecases and Patterns, of classes, interfaces and inheritance. But those things are tools made to help us model the simplest code possible to solve the problem.

当然,我们将使用UI,数据库,用例和模式,类,接口和继承。 但是这些东西都是用来帮助我们为解决问题的最简单代码建模的工具。

Each part of the domain has a different problem. Even if they all look like the same CRUD. One part of the system is going to need an Entity with data in the constructor, another part is going to need an Entity that is born inside a Gateway. Another part is going to need a Gateway with lots of rules in it. Another is going to have a Usecase that’s only used by other Usecases, and another is going to have them all inline.

域的每个部分都有不同的问题。 即使它们看起来都像相同的CRUD。 系统的一部分将需要一个在构造函数中具有数据的实体,另一部分将需要一个在网关内部生成的实体。 另一部分将需要其中包含许多规则的网关。 另一个将有一个仅由其他用例使用的用例,而另一个将使它们全部内联。

But the question is more important: is this code the simplest possible for now? So be it, because in a little while we’ll learn more and change this code to something better.

但是问题更重要:此代码是目前最简单的代码吗? 就是这样,因为过一会儿我们将学习更多,并将此代码更改为更好的代码。

[1] The book Domain Driven Design addresses some concepts that help to isolate an application from external factors, but the objective is to model the business rules in a consistent way to the business domain — which is very important indeed, and a topic for another article — and doesn’t focus so much on the independence and freedom.

[1]《域驱动设计》一书探讨了一些概念,这些概念有助于将应用程序与外部因素隔离,但目标是以与业务领域一致的方式对业务规则进行建模-这确实非常重要,而另一个主题文章-并没有过多地关注独立性和自由性。

翻译自: https://medium.com/swlh/what-exactly-is-software-architecture-c1c67d1213f3

有什么软件架构属于单体架构