开发者

A little help with MVC

开发者 https://www.devze.com 2022-12-29 06:49 出处:网络
I\'m working on a cocoa app for syncing data between two folders. It have profiles (so you can have multiple setups)

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 divid开发者_开发知识库e it.

Best regards.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号