gif分解合成_如何通过分解和合成使复杂的问题更容易

gif分解合成

Discover Functional JavaScript was named one of the best new Functional Programming books by BookAuthority!

“发现功能JavaScript”BookAuthority评为最佳新功能编程书籍之一

Our natural way of dealing with complexity is to break it into smaller pieces and then put everything back together.

我们处理复杂性的自然方法是将其分解为较小的部分,然后将所有内容放回原处。

This is a two step process:

这是一个两步过程:

  • decompose the problem into smaller parts

    将问题分解成更小的部分
  • compose the small parts to solve the problem

    组成小零件解决问题

We decompose in smaller parts because they are easier to understand and implement. The smaller parts can be developed in parallel.

我们将较小的部分分解,因为它们更易于理解和实施。 较小的部分可以并行开发。

The process of decomposition is about assigning responsibilities and giving names. This makes it easy to talk and reason about. Once we identify a responsibility, we can reuse it.

分解的过程是关于分配职责和给出名称的。 这使得谈论和推理变得容易。 一旦确定了责任,就可以重用它。

Composition is about combining the small parts together and establishing a relationship between them. We decide the way these pieces communicate, the order in which they execute, and how data flows between them.

组成是将小部分组合在一起并在它们之间建立关系。 我们决定这些部分的通信方式,它们执行的顺序以及它们之间的数据流向。

We find a system hard to understand even if it is split in smaller parts, if there is a high number of relations between these parts. In order to make a system easier to understand, we need to minimize the number of possible connections between its parts.

即使这些部分之间存在大量关系,即使将系统分成较小的部分,我们也很难理解。 为了使系统更易于理解,我们需要最大程度地减少系统各部分之间可能的连接数。

对象分解 (Object decomposition)

Objects are more than state and behavior working together. Objects are things with responsibilities.

对象不仅仅是状态和行为协同工作。 对象是有责任的事物。

分解 (Decompose)

In How to create a three layer application with React, I take a to-do list application and split the responsibilities between the following objects :

如何使用React创建一个三层应用程序中 ,我将一个待办事项列表应用程序并在以下对象之间划分职责:

  • TodoDataService : responsible for the communication with the server Todo API

    TodoDataService :负责与服务器Todo API的通信

  • UserDataService : responsible for the communication with the server User API.

    UserDataService :负责与服务器User API的通信。

  • TodoStore : the domain store for managing to-dos. It is the single source of truth regarding to-dos.

    TodoStore :用于管理待办事项的域存储。 这是关于待办事项的唯一事实来源。

  • UserStore : the domain store for managing users.

    UserStore :用于管理用户的域存储。

  • TodoListContainer : the root container component displaying the list of to-dos.

    TodoListContainer :显示待办事项列表的根容器组件。

As you can see, when decomposing, I assign responsibilities and give names.

如您所见,在分解时,我分配职责并给出名称。

撰写 (Compose)

Next, I compose them together in a single function. This is the place where all objects are created and dependencies injected. It is called Composition Root.

接下来,我将它们组合成一个函数。 在这里创建所有对象并注入依赖项。 它称为合成根。

Discover Functional JavaScript was named one of the best new Functional Programming books by BookAuthority!

发现功能JavaScript被称为 BookAuthority最好的新功能编程书籍

For more on applying functional programming techniques in React take a look at Functional React.

有关在React中应用函数式编程技术的更多信息,请查看 Functional React

Learn functional React, in a project-based way, with Functional Architecture with React and Redux.

通过带有React和Redux的功能架构 ,以基于项目的方式学习功能性React

Follow on Twitter

在Twitter上关注

翻译自: https://www.freecodecamp.org/news/how-to-make-complex-problems-easier-by-decomposing-and-composing-be57ce230c49/

gif分解合成

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值