图书馆之间的区别? (目录结构)

发布于 2024-12-01 09:56:54 字数 445 浏览 0 评论 0原文

因此,这里是我当前正在处理的 Web 应用程序上的目录结构的快速摘录:

/app
  /libraries
    User_Input.php
    Database.php
    InvoiceHandler.php

您认为 InvoiceHandler 在这个集合中有点奇怪吗?我当然知道。

直到最近,我还忽略了区分事实上的库(实际上是我的应用程序和其他服务(例如持久存储)之间的中间层)和我自己编写的包含自定义逻辑的代码类的需要。我的应用程序(例如本例中的 Invoice_Handler)。

但随着我的应用程序的增长,这会造成越来越混乱。到目前为止,我还没有看到任何关于这方面的好的例子,而且我没有足够的经验来自己得出结论:

对于这两个明确且明显不同的类别的分离,惯例和常识有何看法?

So, here's a quick extract of the directory structure on a web application that I am working on currently:

/app
  /libraries
    User_Input.php
    Database.php
    InvoiceHandler.php

Do you think that the InvoiceHandler is a bit odd in this collection? I sure do.

Until recently, I have ignored the need to distinguish between de-facto libraries that actually are the middle-layer between my application and other services (such as a Persistent storage) and the classes of code that I have written myself that contains custom logic for my application (such as the Invoice_Handler in this case).

But as my application grows, this creates more and more of a mess. I haven't seen any good examples on this as of today and I have not enough experience to come to a conclusion by myself:

What does conventions and common sense say on separation of these two definite and so clearly different sort of classes?

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

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

发布评论

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

评论(3

雪若未夕 2024-12-08 09:56:54

您可以使用以下结构:

libs
    Common(Core)
        Db
          Connection(Database).php
    Input
         Validator
         Filter
    Handler(Controller)
        Invoice.php
    Model 

You can use the following structure:

libs
    Common(Core)
        Db
          Connection(Database).php
    Input
         Validator
         Filter
    Handler(Controller)
        Invoice.php
    Model 
拿命拼未来 2024-12-08 09:56:54

这个问题有点模糊,显示的示例文件名并没有真正解释它们。然而,我会说你需要将你的课程组合成一个有意义的结构。

/app
  /library
    /My
      /Controller
        AbstractController.php
      /Filter
        CamelCaseToUnderscore.php
        UnderscoreToCamelCase.php
      /Validator
        Date.php
        Url.php

我使用的类与您的类有很大不同(至少我认为是),但您可以清楚地看到它们被分组为逻辑结构。

This question is a bit vague, and the example filenames shown don't really explain much about them. I will however say that you need to group your classes together into a structure that makes sense.

/app
  /library
    /My
      /Controller
        AbstractController.php
      /Filter
        CamelCaseToUnderscore.php
        UnderscoreToCamelCase.php
      /Validator
        Date.php
        Url.php

The classes I've used are vastly different (at least I think they are) from yours, but you can clearly see they are grouped into a logical structure.

柒夜笙歌凉 2024-12-08 09:56:54

我最终根据库包含的抽象级别来分离它们。为了寻找更好的高级抽象名称,我使用了类别名称 services 来表示这些名称,并使用 libraries 来保留低级抽象类。

IE。 :

/common
    /libraries (low-level)
        database.php
        session.php
        email.php
    /services (high-level)
        auth.php (dependent on database + session)
        invoicing.php (dependent on database + email)

I ended up separating my libraries depending on what level of abstraction they contained. In search of a better name of high-level abstraction, I used the category name services for these and retained with libraries for low-level abstraction classes.

Ie. :

/common
    /libraries (low-level)
        database.php
        session.php
        email.php
    /services (high-level)
        auth.php (dependent on database + session)
        invoicing.php (dependent on database + email)
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文