分离模型、视图和控制器的最佳方法 [英] Best approach to separate Model, View, and Controller

查看:21
本文介绍了分离模型、视图和控制器的最佳方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在考虑分离模型视图和控制器的最佳方法——对于 Java 和使用 Eclipse,如果有什么不同的话.

I'm thinking about the best approach to separate Model View and Controller—for Java and using Eclipse, if it makes any difference.

我曾经将每种类型的 MVC 分开放在自己的包中,但我开始认为这不是最好的方法:

I used to separate each type's MVC inside its own package, but I'm start to think that this is not the best approach:

  • com.company.client(控制者)
  • com.company.client.model
  • com.company.client.view

  • com.company.client (controler)
  • com.company.client.model
  • com.company.client.view

com.company.another(控制者)

com.company.another (controler)

com.company.another.view

com.company.another.view

com.company.yetAnother(控制者)

com.company.yetAnother (controler)

(假设有很多不同的包,每个包都有自己的视图和模型)

(assume a lot of different packages, each one with its own view and model)

我考虑过使用:

  • com.company.client
  • com.company.another
  • com.company.yetAnother

  • com.company.client
  • com.company.another
  • com.company.yetAnother

com.company.model.client

com.company.model.client

com.company.model.yetAnother

com.company.model.yetAnother

com.company.view.client

com.company.view.client

我什至考虑将控制器、模型和视图放在不同的项目中.也许它会更加模块化,并且我会更确定视图没有使用控制器,例如(因为控制器项目将包含视图,但不是相反).

I even thought about putting the controller, model, and view in different projects. Maybe it would be even more modular, and I would be more sure that the view is not using the controller, for example (as the controller project would include the view, but not the reverse).

那么分离 M、V 和 C 的最佳方法是什么?

So what is the best approach to separate M, V, and C?

(考虑网络和桌面应用,而不仅仅是网络)

推荐答案

The Graal Quest!你有一个带有垂直(MVC)和水平(业务规则)层的二维矩阵......

The Graal Quest! You have two dimensional matrix with vertical (MVC) AND horizontal (business rules) layers...

  • 我还没有找到严格的答案
  • 您的第一种方法看起来不错,因为模块化面向(可能是无意的)
  • 对于小型应用程序,您的第二个虽然可能可以接受

对我来说,响应是一个词:依赖项
继续在包装设计/策略"中搜索;粒度"

For me response is a word: dependencies
Keep searching in "package design/strategy" ; "Granularity"

一些阅读

我强烈推荐这个:

I strongly recommand this one:

祝你好运!

这篇关于分离模型、视图和控制器的最佳方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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