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

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

问题描述

我正在考虑将模型视图和Controller-for 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( controler)

  • com.company.client.model

  • com.company.client.view

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

com.company.another(controler)

com.company.another (controler)

com.company.another.view

com.company.another.view

com.company.yetAnother(controler)

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?

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

推荐答案

Graal Quest!你有二维矩阵与垂直(MVC)和水平(业务规则)层...

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


  • 我没有找到严格的答案

  • 您的第一种方法看起来不错,因为模块化导向(可能是非预期的)

  • 对于小型应用,您的第二种方法可能是可接受的

  • I haven't found a strict answer
  • Your first approach looks good because modular oriented (unintended maybe)
  • For a small app your second though maybe acceptable

对我来说,回复是一个词:依赖

继续搜索包设计/策略; 粒度

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

一些阅读

  • http://techdistrict.kirkk.com/2009/08/05/modularity-patterns/
  • http://techdistrict.kirkk.com/2010/04/22/granularity-architectures-nemesis/

我强烈推荐这个:

I strongly recommand this one:

好运!

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

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