MVCP (was Re: Using Bindings with C++ objects)
MVCP (was Re: Using Bindings with C++ objects)
- Subject: MVCP (was Re: Using Bindings with C++ objects)
- From: Chris Hanson <email@hidden>
- Date: Wed, 26 Dec 2007 16:16:13 -0800
On Dec 22, 2007, at 2:53 PM, Rick Mann wrote:
I'd like to use bindings to facilitate this (as I understand it,
this is something they're good for). However, they won't work
directly on C++ objects. I was thinking I could subclass
NSArrayController and override the valueForKey: methods to manually
inspect the key path and hard-code queries to the SatelliteProxy
objects. One of my concerns with this approach is that the
NSArrayController's container for the collection of SatelliteProxy
objects may not be able to contain C++ objects.
I'd like to get feedback on this approach. Is it viable? It's okay
if there's extra effort coding up the key-to-C++ mapping. That's
still less work than rewriting my classes as Obj-C.
An alternative is to create a wrapper Obj-C object, one for each
SatelliteProxy object. I do something similar for the view code I
wrote in the Carbon app.
Creating a wrapper for the SatelliteProxy and binding to that will
probably be the easiest thing to do. You'll wind up with less code
than you would trying to override things in NSArrayController (and its
superclasses) to make this work, and your code will be much more
modular.
I'll take this as an opportunity to talk about my MVCP[1]
recommendation for writing cross-platform code, which also works for
writing single-platform code where you're mixing technologies.
Instead of a traditional Model-View-Controller architecture, you split
the controller in two: One part is a Controller which implements the
common model-level "interaction" for your architecture, and the other
part is a Presenter which implements view/framework-specific
controller behavior.
For example, if you're writing an accounting application with a
"record transaction" button, the target of that button would be a
Presenter object. The Presenter would take information from your
views, convert it to the proper form for your
It sounds like you're already doing this, just under different names.
So you don't have very far to go. :)
To extrapolate an example, though, from the couple of classes you've
mentioned, here's how I'd approach the design of the application:
GroundTrackView[V] - a View that displays satellite ground tracks
(ObjC)
GroundTrackPresenter[P] - a Presenter that manages display of
satellite ground tracks (ObjC++)
SatelliteProxy[C] - a Controller to do bookkeeping for satellite
ground tracks (C++)
Satellite[M] - a Model representing a satellite (C++)
For one Satellite I might have one or more SatelliteProxy objects,
each of which would probably be wrapped by or interfaced to by one
GroundTrackPresenter, each of which would be interacted with by one
GroundTrackView.
If I subsequently wanted to implement a .NET, GNOME, or even Web 2.0
version of this application, only the View layer and Presenter layer
code needs to be written anew. The applications logic is in its Model
layer and the interaction with this logic is handled by its Controller
layer.
-- Chris
[1] I used to call this MVCC, where the first controller was a "model
controller" and the second was a "view controller." But Cocoa now has
an NSViewController class that's used for a different purpose, so I've
changed the name of the "view controller" to "presenter." In a lot of
ways it's just Model-View-Presenter but with an extra layer between
the Model and Presenter to handle interaction in a more abstract
fashion. This can also be useful for apps that also want to expose
(say) a scripting API.
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden