Frage

According to the Document-Based Applications Guide, there should be a DocumentController, a Document, and a WindowController. What I am having trouble with is learning to judge where a given responsibility ought to fall.

My Document represents a todo list. A given todo list is read into memory by my Document, and it is displayed by the WindowController. The number of todos that can fit in the window at any time is determined by the size of the window, so when I need to display todos my WindowController asks my Document for enough todos to fill the visible list.

If I want to I can search through my todos using regular expressions (I know, fancy right) and the matches are returned as the top results. In this case I'm less clear on where the responsibilities lie. The Document deals with saving and loading a todo list, but above I have asked it to also deal with returning small parts of the list to the WindowController. Should the matching logic go in the Document then? Or should this stay in the WindowController since it has nothing to do with saving and loading data (the order of todos after a search is never saved to disk)? These are the sorts of questions I find myself asking (myself). When I look back on a project like this one, I notice places where my judgement calls seem at odds with each other. Sometimes I'll spend an hour just moving one bit of logic around between the two... trying to imagine which design makes more sense.

Clearly I need help.

My example is of a very particular situation, but I am not interested in the particular solution. I am interested in knowing in more general terms what the responsibilities of these three classes ought to be. I read the guide and I've googled around a bit, but I still can't seem to get a handle on it.

This question was helpful, but I am still confused.

Thanks!

War es hilfreich?

Lösung

My instinct in this case would be to put the logic in the window controller. The search functionality is not affecting the actual model, and I think of NSDocument as more of a "model-controller".

NSWindowController is a better fit for managing the details of the UI (a "UI-controller"), and essentially you are just controlling the view of the model with your search bar.

Yes, I know that we have NSViewController as well but sometimes that's just additional complexity for the sake of it. Much of the time, NSWindowController is just fine.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top