如何将问题划分为更小的可理解部分?

时间:2022-09-20 14:34:00

I'm not sure if it's possible to give general advice on this topic, but please try. It's hard to explain my case because it's too complex to explain. And that's exactly the problem.

我不确定是否可以就此主题提供一般性建议,但请尝试。很难解释我的案例,因为它太复杂而无法解释。而这正是问题所在。

I seem to constantly stumble on a situation where I try to design some part of my project, but it has so many things to take into consideration that I'm unable to get a grasp of it.

我似乎经常偶然发现我试图设计我项目的某些部分的情况,但它有很多事情要考虑到我无法掌握它。

Are there any general tips or advice on how to look at my system in smaller pieces at a time? How to find smaller portions that could be designed separately on their own?

有关如何一次性查看我的系统的一般提示或建议吗?如何找到可以单独设计的较小部分?

5 个解决方案

#1


Your key goals are:

您的主要目标是:

  • High cohesion: Code (methods, fields, classes) within one piece/module/partition should interact intensively; it should make sense for these elements to know about each other. If you find that some of them don't interact much with the rest, they probably belong somwhere else or should form their own partition. If you find code outside interacting intensively with the partition and knowing too much about its inner workings, it probably belongs inside. The typical example is found in OO code written in procedural style, with "dumb" data objects and "manager" code that operates on them but should really be part of the data objects.
  • 高内聚性:单件/模块/分区内的代码(方法,字段,类)应该集中交互;这些元素相互了解应该是有意义的。如果您发现其中一些与其他部分没有太多交互,那么它们可能属于其他地方,或者应该形成自己的分区。如果您发现外部代码与分区密切交互并且对其内部工作了解太多,那么它可能属于内部。典型的例子是在以程序风格编写的OO代码中找到的,“哑”数据对象和“管理器”代码对它们进行操作但应该真正成为数据对象的一部分。

  • Loose coupling: Interaction between pieces/modules/partitions should only happen through narrow, well-defined, well-documented APIs. Try to identify such APIs and see what code is needed to implement them and what code will use them.
  • 松耦合:件/模块/分区之间的交互只能通过狭窄,定义明确,记录良好的API来实现。尝试识别此类API并查看实现它们所需的代码以及将使用它们的代码。

#2


Create a glossary.

创建词汇表。

In other words, identify the terms that are meaningful to the project domain — not from the programmer's point of view, but from a user's, who is familiar with the subject matter.

换句话说,确定对项目域有意义的术语 - 不是来自程序员的观点,而是来自熟悉该主题的用户。

Then define the terms as precisely and discretely as you can. A good definition in this form can serve as a kind of pseudocode.

然后尽可能准确地和离散地定义术语。这种形式的良好定义可以作为一种伪代码。

Since you have not identified even the domain of your problem, I'll choose a random example. In a civilian personnel system, you might have terms like:

由于您还没有确定问题的域名,我会选择一个随机的例子。在文职人员系统中,您可能会有以下条款:

  • billet: a term of service (from start date to end date) at a particular grade and step
  • 方坯:特定等级和步骤的服务期限(从开始日期到结束日期)

  • employee: a series of billets associated with a particular SSN
  • 员工:与特定SSN相关的一系列方坯

  • grade and step: row and column in the federal general schedule
  • 等级和步骤:联邦总体时间表中的行和列

And so on. This isn't to identify functional units, as it sounds like you are trying to do, but it's a good preparatory step before doing so, so that you can express your functional steps in well-defined terms.

等等。这不是识别功能单元,因为它听起来像你正在尝试做,但这是一个很好的准备步骤,所以你可以用明确定义的术语表达你的功能步骤。

#3


It's useful to approach problem decomposition both top-down and bottom-up.

从上到下和自下而上处理问题分解很有用。

If you're having trouble splitting a big problem into two or more smaller problems, try to think of the smallest possible problems that will need to be solved. Once those are handled, you may start to see ways to combine them into larger problems as you approach your original large problem.

如果您在将大问题分成两个或更多小问题时遇到困难,请尝试考虑需要解决的最小问题。处理完成后,您可能会开始看到在处理原始大问题时将它们组合成更大问题的方法。

#4


When I find myself copying and pasting chunks of code with minimal adjustments I realize that's a "partition" and then create a class, method, function, or whatever.

当我发现自己以最小的调整复制和粘贴代码块时,我意识到这是一个“分区”,然后创建一个类,方法,函数或其他任何东西。

Actually, the whole object oriented approach is what it's all about. Try thinking of your application as tangible things that do stuff. Write pseudo code describing what the things are and what they do, I find lots of "partitions" this way.

实际上,整个面向对象的方法就是它的全部。尝试将您的应用程序视为有用的东西。编写描述事物是什么以及它们做什么的伪代码,我用这种方式找到了很多“分区”。

#5


Here's a try, kind of wild guess.

这是一个尝试,一种狂野的猜测。

People usually underestimate how long it will take them to do the work. If your project is large, then most likely you'll need several people to work on it, so you can try planning with that in mind. Now a person can be expected to hold just one area in the head, so you'll need to explain to him exactly what kind of task he's supposed to do.

人们通常会低估他们做这项工作需要多长时间。如果您的项目很大,那么很可能您需要几个人来处理它,因此您可以尝试计划这一点。现在一个人可能只能在头部占据一个区域,所以你需要向他解释他应该做什么样的任务。

So I'd say you should try to write a job description that should encompass as much as possible for one person to seriously concentrate on. Repeat, until you have broken your project into parts you wanted to. As a benefit, you're ready to assemble your team. But if you find out the parts are small, maybe you'll still be able to do it yourself.

所以我要说你应该尝试写一份工作描述,尽可能地让一个人认真地集中注意力。重复,直到您将项目分解为您想要的部分。作为一项好处,您已准备好组建您的团队。但如果你发现零件很小,也许你仍然可以自己做。

#1


Your key goals are:

您的主要目标是:

  • High cohesion: Code (methods, fields, classes) within one piece/module/partition should interact intensively; it should make sense for these elements to know about each other. If you find that some of them don't interact much with the rest, they probably belong somwhere else or should form their own partition. If you find code outside interacting intensively with the partition and knowing too much about its inner workings, it probably belongs inside. The typical example is found in OO code written in procedural style, with "dumb" data objects and "manager" code that operates on them but should really be part of the data objects.
  • 高内聚性:单件/模块/分区内的代码(方法,字段,类)应该集中交互;这些元素相互了解应该是有意义的。如果您发现其中一些与其他部分没有太多交互,那么它们可能属于其他地方,或者应该形成自己的分区。如果您发现外部代码与分区密切交互并且对其内部工作了解太多,那么它可能属于内部。典型的例子是在以程序风格编写的OO代码中找到的,“哑”数据对象和“管理器”代码对它们进行操作但应该真正成为数据对象的一部分。

  • Loose coupling: Interaction between pieces/modules/partitions should only happen through narrow, well-defined, well-documented APIs. Try to identify such APIs and see what code is needed to implement them and what code will use them.
  • 松耦合:件/模块/分区之间的交互只能通过狭窄,定义明确,记录良好的API来实现。尝试识别此类API并查看实现它们所需的代码以及将使用它们的代码。

#2


Create a glossary.

创建词汇表。

In other words, identify the terms that are meaningful to the project domain — not from the programmer's point of view, but from a user's, who is familiar with the subject matter.

换句话说,确定对项目域有意义的术语 - 不是来自程序员的观点,而是来自熟悉该主题的用户。

Then define the terms as precisely and discretely as you can. A good definition in this form can serve as a kind of pseudocode.

然后尽可能准确地和离散地定义术语。这种形式的良好定义可以作为一种伪代码。

Since you have not identified even the domain of your problem, I'll choose a random example. In a civilian personnel system, you might have terms like:

由于您还没有确定问题的域名,我会选择一个随机的例子。在文职人员系统中,您可能会有以下条款:

  • billet: a term of service (from start date to end date) at a particular grade and step
  • 方坯:特定等级和步骤的服务期限(从开始日期到结束日期)

  • employee: a series of billets associated with a particular SSN
  • 员工:与特定SSN相关的一系列方坯

  • grade and step: row and column in the federal general schedule
  • 等级和步骤:联邦总体时间表中的行和列

And so on. This isn't to identify functional units, as it sounds like you are trying to do, but it's a good preparatory step before doing so, so that you can express your functional steps in well-defined terms.

等等。这不是识别功能单元,因为它听起来像你正在尝试做,但这是一个很好的准备步骤,所以你可以用明确定义的术语表达你的功能步骤。

#3


It's useful to approach problem decomposition both top-down and bottom-up.

从上到下和自下而上处理问题分解很有用。

If you're having trouble splitting a big problem into two or more smaller problems, try to think of the smallest possible problems that will need to be solved. Once those are handled, you may start to see ways to combine them into larger problems as you approach your original large problem.

如果您在将大问题分成两个或更多小问题时遇到困难,请尝试考虑需要解决的最小问题。处理完成后,您可能会开始看到在处理原始大问题时将它们组合成更大问题的方法。

#4


When I find myself copying and pasting chunks of code with minimal adjustments I realize that's a "partition" and then create a class, method, function, or whatever.

当我发现自己以最小的调整复制和粘贴代码块时,我意识到这是一个“分区”,然后创建一个类,方法,函数或其他任何东西。

Actually, the whole object oriented approach is what it's all about. Try thinking of your application as tangible things that do stuff. Write pseudo code describing what the things are and what they do, I find lots of "partitions" this way.

实际上,整个面向对象的方法就是它的全部。尝试将您的应用程序视为有用的东西。编写描述事物是什么以及它们做什么的伪代码,我用这种方式找到了很多“分区”。

#5


Here's a try, kind of wild guess.

这是一个尝试,一种狂野的猜测。

People usually underestimate how long it will take them to do the work. If your project is large, then most likely you'll need several people to work on it, so you can try planning with that in mind. Now a person can be expected to hold just one area in the head, so you'll need to explain to him exactly what kind of task he's supposed to do.

人们通常会低估他们做这项工作需要多长时间。如果您的项目很大,那么很可能您需要几个人来处理它,因此您可以尝试计划这一点。现在一个人可能只能在头部占据一个区域,所以你需要向他解释他应该做什么样的任务。

So I'd say you should try to write a job description that should encompass as much as possible for one person to seriously concentrate on. Repeat, until you have broken your project into parts you wanted to. As a benefit, you're ready to assemble your team. But if you find out the parts are small, maybe you'll still be able to do it yourself.

所以我要说你应该尝试写一份工作描述,尽可能地让一个人认真地集中注意力。重复,直到您将项目分解为您想要的部分。作为一项好处,您已准备好组建您的团队。但如果你发现零件很小,也许你仍然可以自己做。