0

A lot of applications with a GUI can be seen as handling a collection of objects (probably at several levels). For instance, a list of contacts or a set of documents. Moreover, maybe there exists the concept of "current object" (current contact, current document or the like) in the application and some GUI controls make actions happen on this current object (and not on other objects in the collection). Obviously, the GUI should offer a way for selecting a different object as "the new current one" before applying new actions on it. I think it is a quite general situation, so maybe there is a quite general solution to where to place such a concept (for instance, an integer index on a list) in the MVC pattern.

I feel it should be out of the Model (I can think of an application with several View/Controller pairs sharing one Model and where each View has its own opinion on which object is the selected or current one), but I have not been able to confirm it by "googling".

I would like to know pointers to authors discussing this subject. Moreover, your opinion is welcome (if such kind of discussion is allowed in this forum). Thanks.

1 Answers1

1

Disclaimer: my primary language is PHP, and only have experience with MVC-related patterns in the context of web (mostly with the Model2 variant of it, because of the obvious limitations of web itself), which has shaped my understanding of MVC structure.

I see the concept of Current Object as an aspect of Model Layer's state. Current object should not directly exposed to other parts of MVC triad. Both the controller(s) and view(s) have only access to it via the higher/public part (I tend to call that part "Services", but it's a bad name) of the model layer.

This lets you freely change, manipulate and swap objects, which you have marked as "current". At the same time other parts of MVC are not directly affected.

As for the materials on subject, I have not really seen any articles/books dealing exclusively with this subject. The best I can suggest is reading Patterns of Enterprise Application Architecture .. again.

Community
  • 1
  • 1
tereško
  • 58,060
  • 25
  • 98
  • 150
  • Thanks for your kind answer, that I had not read until some minutes ago. After a week without response, I thought my question wasn't interesting enough to be answered. Sorry. I appreciate your opinion, though I don't fully understand it, maybe because Model 2 is not the context I am used to. Thanks again. – federico.prat Oct 10 '12 at 21:22