可可MVC:应将应用程序工作逻辑放在哪里? [英] Cocoa MVC: where is application work logic intended to be placed?

查看:90
本文介绍了可可MVC:应将应用程序工作逻辑放在哪里?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Apple开发人员站点上看到的所有Cocoa MVC文档都在诸如数据"之类的实体上运行:模型包含数据",控制器显示数据",视图确保该数据往返传输.但是,仅当您创建数据库访问应用程序(例如"calendar"或"contacts")时,这种方法才是好方法:(.

All Cocoa MVC documentation I see on the apple dev site operates on entities like "data": model holds "data", controller displays "data", view ensures that data and transferred forth and back. But such approach is good only if you create a database access application like "calendar" or "contacts" :(.

但是其他一些应用程序类型又在哪里呢?例如,让我们以一个GUI"ping"应用程序为例,该应用程序创建一个单独的线程,对远程计算机执行ping操作,并绘制一个漂亮的ping响应时间图.可可MVC中实际的ping代码在哪里?是在模型,控制器内部还是在MVC外部?

But where are some other application types? For example, let's take a GUI "ping" application that creates a separate thread, pings remote computer and draws a nice graph of ping response times. Where actual ping code goes in Cocoa MVC? Is it inside model, controller or outside MVC?

下一个示例是锁定屏幕"实用程序,该实用程序显示GUI来配置快捷方式,该快捷方式将锁定OSX屏幕并处理该快捷方式.实际的应用程序逻辑是快捷方式句柄代码和用于检查快捷方式尚未使用的代码.是在模型中,在控制器中还是在MVC之外?

Next example is "lock screen" utility that displays GUI to configure the shortcut that will lock OSX screen and will handle this shortcut. Actual app logic is the shortcut handle code and the code that will check that shortcut is not already used. Is it in model, in controller or outside MVC?

应用程序的一部分,例如在启动时检查新版本"-是在模型,控制器内部还是在MVC外部?

Parts of application like "check new version on startup" - is it inside model, controller or outside MVC?

我很好奇,苹果有没有官方的信息/指南来突出提到的问题?还是对于Apple而言,所有应用程序都是数据库前端? :(

I'm curious, are there any official info / guides from Apple that highlight mentioned questions? Or for Apple all applications are database frontends? :(

推荐答案

MVC体系结构适用于各种应用程序类型,而不仅仅是以数据为中心的应用程序.例如:

The MVC architecture works for a wide variety of application types, not just data-centric applications. For example:

  • GUI ping应用程序应该具有一个模型,该模型可以跟踪主机列表,它们的当前状态以及它们的响应时间. "ping"本身的动作通常被称为控制器功能.我可能会创建一个PingManager对象来对此进行集中管理.或者,您可以有单独的HostController对象,这些对象管理ping服务器并更新了Host模型对象.这不应与HostViewController混淆.控制器可以协调模型对象,而无需视图对象.

  • A GUI ping application should have a model that keeps track of the list of hosts, their current status, and their response times. The act of "pinging" itself would generally be called a controller function. I would likely create a PingManager object that centralized this. Alternately, you could have individual HostController objects that managed pinging the server and updated a Host model object. This should not be confused with a HostViewController. Controllers can coordinate model objects without requiring view objects.

处理程序与快捷方式系统之间的交互将是一种控制器功能.

Handling the interaction between the program and the shortcut system would be a controller function.

版本启动检查通常是应用程序控制器功能,尽管它可以是其自己的控制器对象(例如UpdateManager).

Version startup checks would generally be an application controller function, though it could be its own controller object (an UpdateManager for instance).

通常来说,您最常称为应用程序逻辑"的是控制器.

Generally speaking, what you would most call "application logic" goes in controllers.

这篇关于可可MVC:应将应用程序工作逻辑放在哪里?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆