简体   繁体   English

在D中重构模块化结构

[英]refactoring modular structures in D

Here's how I usually develop an application: 以下是我通常开发应用程序的方法:

  • I start with having all the code in a single source file. 我首先将所有代码放在一个源文件中。
  • When it grows enough to be modularised, I break the code into several modules. 当它增长到足以模块化时,我将代码分成几个模块。
  • When the modules grow enough, I split them again. 当模块增长足够时,我再次拆分它们。 And so on, iteratively. 等等,迭代地。
  • Over time, some modules get shrunk, deleted or merged with others. 随着时间的推移,一些模块会缩小,删除或与其他模块合并。

This workflow implies the need to move source files between modules sometimes. 此工作流程意味着有时需要在模块之间移动源文件。 And here comes the problem: 这就是问题所在:

When I move a module to another location, it changes the module's name, so I have to walk through all the other files renaming imports by hand. 当我将模块移动到另一个位置时,它会更改模块的名称,因此我必须遍历所有其他文件,手动重命名导入。

Is there some organisational technique to avoid that annoying procedure? 是否有一些组织技术来避免这种烦人的程序? Or is that the way it goes and I just have to look into some automation utilities instead? 或者它是这样的,我只需要研究一些自动化实用程序?

you can create a *.all module that public import s all modules in the package 你可以创建一个*.all模块, public import包中的所有模块

then you only need to add/remove the module names from that module 那么你只需要添加/删除该模块中的模块名称

You can override module name via module packagename.modulename; 您可以通过module packagename.modulename;覆盖模块名称module packagename.modulename; directive in the beginning of the module. 模块开头的指令。 It will need a help from the build system though as rdmd uses module names from import statements to form file system path to search for their sources. 虽然rdmd使用import语句中的模块名来形成文件系统路径来搜索它们的源,但它需要构建系统的帮助。 But if you will supply all source files project consists from by hand, it should resolve module names just fine. 但是,如果你将手工提供项目所包含的所有源文件,它应该解决模块名称就好了。

It's better to define your entities before you start coding. 在开始编码之前最好定义实体。 You can use some modelling language to identify and write your entities. 您可以使用某种建模语言来识别和编写实体。 For example if you are using java to code your application then you can use UML to model this application. 例如,如果您使用Java编写应用程序代码,那么您可以使用UML为此应用程序建模。

Also, you have to separate buisness logic from data. 此外,您必须将商务逻辑与数据分开。

If you continue to do it like today you will lose a lot of time just dealing with filenames. 如果你像今天一样继续这样做,你将失去很多时间来处理文件名。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM