简体   繁体   English

MVC:一种模式,多种应用

[英]MVC: One model, multiple applications

I am starting a project based on multiple webapplications (Website, ControlPanel, RestAPI) each based on the same Data[bases] and an MVC framework. 我正在启动一个基于多个Web应用程序(网站,ControlPanel,RestAPI)的项目,每个Web应用程序都基于相同的Data [base]和MVC框架。

To avoid parallel code maintenance I thought of having the same model-files for each app. 为了避免并行代码维护,我考虑为每个应用程序使用相同的模型文件。 But when thinking deeper all possible approaches have some pro's and con's. 但是,当进行更深入的思考时,所有可能的方法都有其优点和缺点。 I thought I'd ask some experts. 我以为我会问一些专家。

Possible ways to go (I know of) : 可能的方法(我知道):


1. Plugin ~one4all 1.插件 〜one4all

The very core of logic encapsuled as a plugin which is deployed in each app. 逻辑的核心被封装为一个在每个应用程序中部署的插件。

++ Only one model per table for all apps ++每张表所有应用程序仅一个模型

-- One bug can crash 4 apps -一个错误可以使4个应用程序崩溃

-- lots of unused code per app -每个应用程序有很多未使用的代码


2. Duplicated code ~all4one 2.重复的代码 〜all4one

Double maintenance of duplicated model files. 双重维护重复的模型文件。

++ Bugs affect only one app ++错误仅影响一个应用

++ Models does not contain unused code ++模型不包含未使用的代码

-- Inefficient development -开发效率低下


3. Api between apps ~lonewolves 3.应用之间的 Api〜lonewolves

Apps get its data from an api. 应用程序从api获取其数据。

++ one code serves all apps ++一个代码可为所有应用程序提供服务

-- uncommon approach -不常见的方法

-- massive overhead -大量开销


4. Models symlinked ~lazy1 4.模型 符号 链接 〜lazy1

One application holds the model files, the other apps will symlink/include it. 一个应用程序保存模型文件,其他应用程序将符号链接/包含该文件。

++ almost no extra work to do ++几乎没有多余的工作要做

+- seems hilarious +-似乎很有趣

-- one bug affects all apps -一个错误会影响所有应用

-- could restrict debugging -可能限制调试


Are there more possible approaches? 还有更多可行的方法吗? Which one is common/recommended? 哪个是常见/推荐的? I don't want to combine the functionality of all apps into one to avoid crashing the whole thing with one pull. 我不想将所有应用程序的功能合并为一个,以避免一键崩溃整个应用程序。

More approaches and ideas are very welcome. 欢迎更多的方法和想法。 Thank you in advance. 先感谢您。

Implement SOLID in proyect. 在proyect中实施SOLID。 Valid all framework. 有效的所有框架。

One option you missed is to keep the projects as one. 您错过的一种选择是将项目保留为一个。 Instead of splitting the model, and thus maintaining it across three or more separate projects, you could make only one project, and just divide the portions with controllers. 无需拆分模型,而是将其维护在三个或更多的独立项目中,您可以仅创建一个项目,并使用控制器将各个部分分开。 Although this method can create a monster of a project, it can also be kept in one place, and many controllers can divide the project down into easily managed pieces. 尽管此方法可以创建项目的怪物,但也可以将其保存在一个地方,并且许多控制器可以将项目划分为易于管理的部分。

If it were me, and I wanted to keep the projects as separate cakephp projects, I would probably end up duplicating code. 如果是我,并且我想将项目保留为单独的cakephp项目,那么我可能最终会重复代码。 It's not that bad to copy and paste. 复制和粘贴还不错。 That's what I do on a website that I work on, in order to separate testing and production. 这就是我在自己工作的网站上所做的工作,以便将测试和生产分开。

Although, I would also probably try including separate files, which contain the same code. 虽然,我也可能会尝试包括单独的文件,这些文件包含相同的代码。 Even though you are using cakephp, you can also use php code. 即使您使用cakephp,也可以使用php代码。 What if you require() files that contain cakephp logic. 如果您的require()文件包含cakephp逻辑,该怎么办。 Not sure if this works, but I would at least give it a try. 不知道这是否有效,但我至少会尝试一下。

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

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