views:

72

answers:

2

Hi everyone,

I'm working on a cocoa app for syncing data between two folders.

  • It have profiles (so you can have multiple setups)
  • It's possible to analyze data
  • It's possible to sync the data

Im a little confused. First of all i cant really see where to have a model? And how many controller would you suggest? 1 WindowController or AnalyzeController, SyncController etc.

Its quite a while since i have worked with MVC. I've read some articles but i'm missing concrete examples on how to divide it.

Best regards.

+1  A: 

The data model handles the data and the abstract relationships between different pieces of the data. The controllers handle the concrete operations of a computer or human interface.

The key division is that the data model doesn't know where the data comes from and doesn't care. For example, it could model a folder and its contents but the actual information in the model could come from a real folder on a disk or it could come from completely made up plist file or it could come from a simulated UI of a folder. The data model doesn't care because it has no direct connection with concrete reality. It just holds an abstract description of the data.

The controllers by contrast are tied to a specific concrete interface. For example, if you have two folders, you would have specific controllers for each folder. Each controller would have concrete knowledge of the real world pathway to the folder as well as the mechanism for reading and writing to the folders. So, if one folder is on the local hard drive and another is remote, each controller would understand the difference. If you have a UI, then the UI would have its own controller.

The controllers job is to translate from the concrete reality to the abstract model. In this case, the controller would handle connecting to a remote server, scanning the folder and then converting that information to an abstract form it would hand off to the data model. However, the controller doesn't save an data and doesn't understand how the pieces of data relate to each other.

In the case of a syncing app, it would be the job of the data model to understand what files where in which folder and what files needed to be copied or updated and to where. It would then tell each controller which files to manipulate. However, the controller wouldn't know why each file was being manipulated.

The design goal is to create a data model that would model the folders and files regardless of where they reside, how they are concretely manipulated or even whether they actually exist at all. That way, you can easily add or remove interfaces just by adding or removing a controller. The controllers themselves are simple because they hold no data and no data manipulation logic.

TechZen
I'd do it the other way: Have an abstract Folder class, but also have concrete classes that handle specifics of accessing a (real or pretend) folder somewhere. My AnalysisController and SyncController (I don't know from the question whether I'd make them the same object or not) would see and interact with the objects only as abstract Folders. I would not have a separate controller for every kind of folder.
Peter Hosey
A: 

First of all thank you all for your responses.

It is still a bit unclear for me how it should be build. Could we be a bit more specific on how to divide the MVC in my concrete case?

s0mmer