在 MVC 框架下,其他开发人员会期望哪种目录结构? [英] Under an MVC framework, which directory structure would be expected by other developers?

查看:15
本文介绍了在 MVC 框架下,其他开发人员会期望哪种目录结构?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

通常,MVC 框架的结构类似于:

Generally, MVC frameeworks have a structure that looks something like:

/models
/views
/controllers
/utils

但是,在 Web 应用程序套件中,我认为将所有模型、视图和控制器聚集在一起可能不是最好的方法,除非我将系统视为一个应用程序而不是应用程序套件.但是,有些东西将每个应用程序"联系在一起,例如用户和用户角色的概念.

However, in a web application suite, I've decided that clumping all models, views, and controllers together probably wouldn't be the best for clarity, unless I treated the system as one application instead of an application suite. However, some things tie every "application" together, like the notion of users and user roles.

所以我有三种可能的解决方案:

So I have three possible solutions:

(1) 做我不想做的事,将每个模型、视图和控制器放在一起,不管它属于哪个应用程序.这将套件视为单个应用程序,因为它们被包括用户在内的多个公共线程捆绑在一起.

(1) Do what I don't really want to do, and keep every model, view, and controller together, regardless of which app it belongs to. This is treating the suite as a single application, since they are tied together by several common threads, including users.

(2) 按应用对代码进行分组.

(2) Group the code by application.

/app1
    /models
    /views
    /controllers
    /utils
/app2
    /models
    /views
    /controllers
    /utils

(3) 按类型对代码进行分组,让所有应用程序共享实用程序代码.

(3) Group the code by type, letting utility code be shared among all of the applications.

/models
    /app1
    /app2
/views
    /app1
    /app2
/controllers
    /app1
    /app2
/utils

有没有我错过的选项?对于未来的开发人员来说,最合乎逻辑的方案是什么?我个人更喜欢 2 和 3,但也许大多数人会期望 1.

Is there an option I missed? What would be the most logical scheme for future developers? I personally prefer 2 and 3, but perhaps most people would expect 1.

推荐答案

看起来 2) 将是你最好的选择,假设你想要一些应用程序的分离.您还可以在/app#"级别有一个/common"文件夹,用于跨所有应用程序共享资源……例如共享实用程序类或其他.

It seems like 2) would be your best option, assuming you want some separation of applications. You could also have a "/common" folder at the "/app#" level for shared resources across all applications... like a shared utility class or whatever.

这篇关于在 MVC 框架下,其他开发人员会期望哪种目录结构?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆