tell-dont-ask

Can I use mvc without getters and setters?

ぃ、小莉子 提交于 2019-12-11 03:56:11
问题 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? 回答1: The render method comes the closest to not exposing state. Another method (well-known to

Aren't Information Expert & Tell Don't Ask at odds with Single Responsibility Principle?

落爺英雄遲暮 提交于 2019-11-30 11:54:02
问题 Information-Expert , Tell-Don't-Ask , and SRP are often mentioned together as best practices. But I think they are at odds. Here is what I'm talking about. Code that favors SRP but violates Tell-Don't-Ask & Info-Expert: Customer bob = ...; // TransferObjectFactory has to use Customer's accessors to do its work, // violates Tell Don't Ask CustomerDTO dto = TransferObjectFactory.createFrom(bob); Code that favors Tell-Don't-Ask & Info-Expert but violates SRP: Customer bob = ...; // Now Customer