[LRUG] Encapsulation/Responsibility delegation and API versioning.

Graham Ashton graham at effectif.com
Mon Aug 22 09:18:52 PDT 2011


On 22 Aug 2011, at 16:16, Ian Leitch wrote:

> The smell that's now beginning to emerge is that controllers are
> getting fat with protected helper methods that build data structures
> for conversion into JSON.

Converting data to JSON sounds like presentation layer to me; you could think of it an as an alternative view.

> What solutions have other people used for this problem?

It reminds me a lot of how the presenter pattern often gets used in Rails, with presenter classes getting stored in app/presenters.

> I'm almost considering a layer in between my controllers and models,
> almost like a presentation layer from model to controller.

From what you've described, it sounds to me as though the layer you're missing wouldn't sit between those two, but would replace the view.

> Mixins could help here... perhaps something like this?

Rather than mix some rendering API into a model, I'd make rendering objects and initialise them by passing a model in. Let them get any data they need from the model and encapsulate the logic about how to create JSON in the renderer.


More information about the Chat mailing list