我可以在没有getter和setter的情况下使用mvc吗? [英] Can I use mvc without getters and setters?
问题描述
如果我不想公开对象的状态,但是仍然需要显示它(假设使用HTML,XML或JSON),那么我将如何在MVC环境中进行显示. 有一个导出方法可以导出一个笨拙的不可变对象(如果可以的话,可以称为数据类")是否有意义. 添加与接口交互的render方法怎么样? 还有其他方法可以解决这个问题吗?
If I don't want to expose the state of my object, but I still need to display it (in HTML, XML or JSON let's say), how would I go about doing that in an MVC environment. Does it make sense to have an export method which exports a dumbed down immutable object (a "data class" if you will). What about adding in a render method which talks to an interface? Are there any other approaches to this problem?
推荐答案
render方法最接近未公开状态.另一种方法(对于Smarty用户来说是众所周知的)是提供视图非对象数据结构以供使用.
The render method comes the closest to not exposing state. Another method (well-known to Smarty users) is to feed the view non-object data structures to work with.
但是,值得一提的是,这些抽象和/或隐藏的接口正在解决的问题是什么?如果您要进行所有这些工作,那么IMO应该确保有一些工作可以为您省钱.
It's worth asking, though, what is the problem that these abstractions and/or the interface hiding they serve are solving? If you're going to be doing all this work, IMO you should make sure there's some work it's saving you.
这篇关于我可以在没有getter和setter的情况下使用mvc吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!