I'm coding a menu, that might look something like this:
I wanted to code this using the MVC pattern. So I started drawing a UML class diagram for the model, and got this:
But I wasn't开发者_开发知识库 happy. I couldn't come up with a good interface for the controller to interact with. Then I realized that for example the NumberMenuItem itself could (should) be split up in to a model, a view and a controller. The model would be the number. The controller would be the - and + used to decrement and increment the number. And the view would be the label displaying the current numeric value. The other MenuItem subclasses can also be split up in MVC parts.
So now the question is:
How do I model this now that CommandMenuItem, NumberMenuItem, StringMenuItem, and SubMenuItem are actually MVC triads themselves but on a lower level?
P.S.
The implementation will allow for example a NumberMenuItem to come in the middle of a menu (showing only - # +, i.e. without any descriptive text), but my external API will make sure that NumberMenuItems and StringMenuItems are always the sole item in a submenu, like in the sketch I posted. Might hide the titlebar of the submenu though.I think I've got something that could work now.
I made lower level MVC triads where the lower level model is part of the bigger model. Same for the controller and view.
Only thing I've been able to find about this on the web is this: http://www.purpletech.com/articles/mvc/mvc-and-beyond.html
精彩评论