你如何组织你的代码库?

发布于 2024-07-21 04:30:25 字数 491 浏览 15 评论 0原文

我很想知道人们如何组织他们的代码库,特别是在可重用组件方面。 我在下面用面向对象的术语进行讨论,但我也对您如何组织其他类型语言的库感兴趣。

例如:

  • 您是否对所有内容都坚持使用类库项目,还是更喜欢将所有内容保留在一个项目中?
  • 您是否重用预构建的 DLL,或者是否在当前工作中包含以前项目中的各个类? 如果是单独的类,您是否在项目之间共享它们以确保所有类都保持最新,或者您是否允许分支?
  • 您的可重复使用元素有多大? 他们有多专注? 他们的注意力如何集中?
  • 通过您的首选实践,您能达到什么程度的重用?

编辑

我不是在

这里寻找具体的指导,我只是对人们的想法和实践感兴趣。 我对不同项目之间(而不是单个项目内)代码的重用特别感兴趣。 (不幸的是,这里使用“项目”具有误导性 - 我的意思是为客户进行的实际项目之间的重用,而不是 Visual Studio 意义上的项目。)

I am interested to know how people organise their code libraries, particularly with respect to reusable components. I am talking in OO terms below but I am interested in how your organise libraries for other types of language also.

For example:

  • Are you a stickler for class library projects for everything or do you prefer to keep everything in a single project?
  • Do you reuse your prebuilt DLLs or do you include individual classes from previous projects in your current work? If individual classes, do you share them between the projects to ensure all are kept up to date or do you permit branching?
  • How large are your reusable elements? How focussed are they? How are they focussed?
  • What level of reuse do you attain through your preferred practices?

etc.

EDIT

I am not looking for specific guidance here, I am just interested in people's thoughts and practices. I am particularly interested in the reuse of code between disparate projects, rather than within a single project. (Unfortunately the use of 'project' here is misleading - I mean reuse between real-world projects undertaken for customers, not projects in a Visual Studio sense.)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

残龙傲雪 2024-07-28 04:30:25

通常可以通过部署注意事项来指导:

您将如何部署(即您将在生产计算机上复制什么)?

如果您要部署的是打包组件(即dll、jar、war...),那么明智的做法是将“代码库”组织为打包的集合文件集。
这样,您将直接使用 dll、jar、war 等进行开发,这些将部署在生产平台上。
这个想法是:如果它可以与这些打包文件一起使用,那么它仍然可以在生产中使用。


在不同项目之间(而不是在单个项目内)重用代码。

我认为这种重用在“组件”方法中更容易(就像问题“GIT 中的供应商分支”)

在当前的 40 多个项目中,我们

  • 通过系统地将任何纯技术方面隔离到独立的框架(通常是日志框架、异常框架)中,实现了:技术重用 、KPI - 关键绩效指标 - 框架等)。
    这些技术组件被重用到所有其他项目中。
  • 通过设置清晰的应用架构来功能重用,以便将任何功能域(给定业务和功能规范)划分为明确定义的应用程序。 例如,这通常涉及总线层,它也是公开任何其他项目重用的服务的绝佳候选者。

摘要:
对于大型功能域,单个项目难以管理,良好的应用架构将导致自然的代码重用。

It generally can be guide by deployment considerations:

How will you deploy (i.e. what will you copy on your production machine) ?

If what you are deploying are packaged components (i.e. dll, jar, war, ...), it is wise to organize the "code library" as a collection of packaged set of files.
That way, you will develop directly with the -- dll, jar, war, ... -- which will be deployed on the production platform.
The idea being: if it works with those packaged files, it may still work in production.


the reuse of code between disparate projects, rather than within a single project.

I maintain that kind of reuse is easier in a "component" approach (like the one discussed in the question "Vendor Branches in GIT")

Over more than 40 current projects, we achieved:

  • technical reuse by systematically isolating any pure technical aspect into independent framework (typically, log framework, exception framework, KPI - Key Performance Indicator - framework, and so on).
    Those technical components are reused into every other projects.
  • functional reuse by setting a clear applicative architecture in order to divide any functional domain (given the business and functional specifications) into well-defined applications. That would typically involve, for instance, a bus layer which is also a great candidate for exposing services reused by any other projects.

Summary:
For large functional domain, a single project being not manageable, a good applicative architecture will lead to natural code reuse.

污味仙女 2024-07-28 04:30:25

我们遵循以下原则:

  • 发布-重用等效原则:重用的粒度就是发布的粒度。
  • 公共封闭原则:包中的类应该一起封闭以防止相同类型的更改。
  • 通用重用原则:包中的类可以一起重用。
  • 非循环依赖原则:包依赖图中不允许出现循环。
  • 稳定依赖原则:依赖于稳定的方向。
  • 稳定抽象原则:包应该既抽象又稳定。

您可以通过此处此处

We follow these principles:

  • The Release-Reuse Equivalency Principle: The granule of reuse is the granule of release.
  • The Common Closure Principle: The classes in a package should be closed together against the same kinds of changes.
  • The Common Reuse Principle: The classes in a package are reused together.
  • The Acyclic Dependencies Principle: Allow no cycles in the package dependency graph.
  • The Stable Dependency Principle: Depend in the direction of stability.
  • The Stable Abstraction Principle: A package should be as abstract as it is stable.

You can find out more over here and over here.

情定在深秋 2024-07-28 04:30:25

这取决于你工作的平台。 我是一名(自豪的)Java 开发人员,我们有很好的工具来组织我们的依赖项,例如 Maven常春藤

It depends on what platform you work. I'm a (proud) Java developer and we have nice tools to organise our dependencies such as Maven or Ivy

陌伤浅笑 2024-07-28 04:30:25

无论您决定做什么,良好的源代码控制对此都至关重要,因为它允许您以任何您喜欢的方式实施您的策略,而不会最终产生大量不相关的库副本。良好的分支支持至关重要。

Whatever else you decide good source code control is crucial to this,as it allows you to implement your strategy whatever way you like without ending up with lots of unrelated copies of your libraries.good branching support is essential.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文