# 模块化 Modularity


# Grade 2 ( 5-7岁 ) 要掌握的程度

Complex tasks can be broken down into simpler instructions, some of which can be broken down even further. Likewise, instructions can be combined to accomplish complex tasks.

Decomposition is the act of breaking down tasks into simpler tasks. An example of decomposition is preparing for a party: it involves inviting guests, making food, and setting the table. These tasks can be broken down further. For example, setting the table involves laying a tablecloth, folding napkins, and placing utensils and plates on the table. Another example is breaking down the steps to draw a polygon.

Composition, on the other hand, is the combination of smaller tasks into more complex tasks. To build a city, people build several houses, a school, a store, etc. To create a group art project, people can paint or draw their favorite ocean animal, then combine them to create an ecosystem.

Crosscutting Concept: System Relationships Connection Within Framework: K–2.Computing Systems.Devices

复杂的任务可以被分解成更简单的指令, 同样地, 指令也可以组合起来完成复杂的任务.

“分解”是指将任务分解为更简单的任务. 比如准备聚会的任务, 可以将其分解成邀请客人、制作食物、布置餐桌. 这些任务还可以进一步分解, 比如布置餐桌可以分解成铺设桌布、折叠餐巾、将餐具和盘子放在桌子上. 另一个关于分解的例子是将绘制多边形的步骤进行分解.

另一方面, “组合”是将小的任务组合成复杂的任务. 比如, 人们通过建造几座房子、一所学校、一家商店等等来为了建造一座城市. 再比如, 打架可以绘制各自最喜欢的海洋动物, 然后按照自然的生态系统将这些作品组合起来, 这就形成了一个集体的艺术项目.


# Grade 5 ( 8-11岁 ) 要掌握的程度

Programs can be broken down into smaller parts to facilitate their design, implementation, and review. Programs can also be created by incorporating smaller portions of programs that have already been created.

Decomposition facilitates aspects of program development, such as testing, by allowing people to focus on one piece at a time. Decomposition also enables different people to work on different parts at the same time. An example of decomposition at this level is creating an animation by separating a story into different scenes. For each scene, a background needs to be selected, characters placed, and actions programmed. The instructions required to program each scene may be similar to instructions in other programs.

Crosscutting Concepts: System Relationships; Abstraction

程序可以被分解成较小的部分, 以方便设计、实施、检查. 程序也可以通过组合已经创建的小的程序来创建.

“分解”促进了程序开发的各个方面, 比如分解之后, 就允许人们一次专注于一个部分的测试. “分解”也使得不同的人能够同时在不同的部分上工作.

对于这个阶段的学生, 可以通过这样一个例子来理解“分解”: 把一个故事分成不同的场景来创建动画, 对于每个场景, 都需要选择背景、放置角色, 并对角色的动作进行编程. 而且很可能不同场景所需的编程指令相互之间是相似的.


# Grade 8 ( 11-14岁 ) 要掌握的程度

Programs use procedures to organize code, hide implementation details, and make code easier to reuse. Procedures can be repurposed in new programs. Defining parameters for procedures can generalize behavior and increase reusability.

A procedure is a module (a group of instructions within a program) that performs a particular task. In this framework, procedure is used as a general term that may refer to an actual procedure or a method, function, or similar concept in other programming languages. Procedures are invoked to repeat groups of instructions. For example, a procedure, such as one to draw a circle, involves many instructions, but all of them can be invoked with one instruction, such as “drawCircle.” Procedures that are defined with parameters are generalizable to many situations and will produce different outputs based on a wide range of inputs (arguments).

Crosscutting Concepts: Abstraction; System Relationships

程序使用流程来组织代码、隐藏实现细节, 并使代码更容易被复用. 程序可以在新的程序中被重新使用. 为程序引入参数变量, 可以涵盖更多的情况、增加复用性.

程序是一个模块, 用于执行一项特定的任务. “程序”是一个通用的术语, 可以指一段程序、函数或其他编程语言中的类似概念. 通过调用程序, 可以重复一组指令. 比如, 一个画圆的程序, 里面包含许多指令, 但是所有这些指令可以只用一条指令来调用. 带有参数的程序可以适用于多种情况, 当输入不同的数据时, 可以产生不同的输出.


# Grade 12 ( 14-18岁 ) 要掌握的程度

Complex programs are designed as systems of interacting modules, each with a specific role, coordinating for a common overall purpose. These modules can be procedures within a program; combinations of data and procedures; or independent, but interrelated, programs. Modules allow for better management of complex tasks.

Software applications require a sophisticated approach to design that uses a systems perspective. For example, object-oriented programming decomposes programs into modules called objects that pair data with methods (variables with procedures). The focus at this level is understanding a program as a system with relationships between modules. The choice of implementation, such as programming language or paradigm, may vary.

Crosscutting Concepts: System Relationships; Abstraction Connection Within Framework: 9–12.Computing Systems.Hardware and Software

复杂的程序被设计成由相互作用的模块组成的系统, 每个模块都有其特定的作用, 为了一个共同的目的而进行组合. 程序通过有序地组合这些模块来实现特定目标, 这些模块可以是数据和程序的组合, 也可以是独立但相互关联的程序. #todo 通过模块, 我们可以更好地管理和完成复杂的任务.

软件应用需要一个复杂的设计方法,使用系统的观点。比如, 面向对象编程将程序分解成“对象”的模块, 赋予其数据和方法(也就是变量和程序). 这个阶段的学生, 要能够把程序理解为一个具有模块间关系的系统.

这种模块组合的实现方式, 在不同编程语言或者范式中, 可能有所不同.