模型视图控制器(MVC):模型和视图控制器数据类型
假设您的(java 或 *)应用程序有一个 N 层 MVC 架构。您选择 MVC 是因为它对应用程序代码进行逻辑、可管理的分区。 假设您喜欢 Java,因为有很多框架或工具,您不想将某个层(M、V 或 C)与特定技术联系起来,并希望保持以后升级甚至集成的自由度与其他零件。
现在,在每种情况下,模型都可能包含原始数据类型(如 Int、String 等),或更高级的类形式的数据类型(面向最大复杂性的 OO 功能)。 你会如何处理这个问题:
- 尽可能将模型保持为 POJO,并在 V 或 C 层实现类型,因为它主要是关于数据输入和验证。这样,你就不必担心你的 Model 会在其他地方使用,在 DAL 上几乎也不会发生任何改变,但你必须付出额外的努力才能将你的模型转换为 rich-model(类型丰富);当您将其从存储传输到视图时,
- 使您的模型能够像其他嵌套模型一样支持类型,并实现 V 或 C 层技巧来处理它,每个层都必须处理模型复合体,而不仅仅是使用 getter 和设置器。然而,通过这种方式,您可以将模型复合体保留在其他技术设置中,而这些技术设置应该进行相应的调整。
- [以上都不是或其他]
Suppose you have an N-Tier, MVC architecture of your (java or *) application. You chose MVC for its logical, manageable partitioning of the application code.
Suppose you are into Java, since there are many frameworks or tools out there, you don't want to tie a Layer (M or V or C) to a specific technology, and would like to maintain the freedom for later upgrades or even integration with other parts.
Now, in every scenario, a Model may contain primitive data types (like Int, String..etc), or more advanced ones in the form of classes (OO features for max complexity).
How would you deal with that:
- keep your Model as POJO as you can, and implement the typing at the V or C layer, since it is mostly about data input and validation . This way, you don't have to worry about your Model being used elsewhere, almost nothing will change at the DAL as well, but you have to do extra effort to convert your model to a rich-model (rich in types); when you transfer it from the storage to the view
- enable your Model to support types as other nested Models, and implement V or C layer tricks to deal with it, each Layer will have to process the model-complex, instead of just using getters and setters. However this way, you keep the model-complex in other technological settings, which should be adapted accordingly.
- [none of the above or else]
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我认为如果你想完全分布式,技术是无关紧要的。我会为每一层创建单独的应用程序,您可以轻松地对其进行集群,然后选择标准化的通信格式,例如基于 HTTP 的 JSON。
JSON 可以像您喜欢的那样简单或复杂,并且几乎每种语言都内置了对其的支持。HTTP
快速而简单,并且非常容易扩展。
只是我的两分钱。
I think the technology is irrelevant if you wanna go fully distributed. I would create separate apps for each layer, which you can easily cluster and then choose a standardized communication format like JSON over HTTP(s).
JSON can be as simple or complex as you like and pretty much every language out there has support for it built in.
HTTP is fast and simple, and very easy to scale.
Just my two cents.