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

查看:59
本文介绍了在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天全站免登陆