Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: AppleScript-Cocoa Impedance Mismatch



On Nov 1, 2007, at 6:43 PM, Major Domo wrote:

On Nov 1, 2007, at 3:13 PM, Jim Correia wrote:
In the terminology if you have a media object, and a book object, the user should be able to access them specifically or generically (I realize this is the other question you asked) and as long as the objects specify them selves, use the class operator to determine what kind they are. In that case, having a type property of media which returns an enumerated value "book" is not necessary; and isn't the norm for how things work.

You're totally right, of course. Now that you have me thinking in AppleScript, I realize that the solution to the class versus type problem is to eliminate the type and not the class. That only leaves one problem: what's best practices for converting between AppleScript's model (type as class) and the actual implementation (type as property).

(OK, obviously the best thing would be to go type as class in the implementation, but at this point that is not an option.)

Solution 1:

Write your -books scripting KVC accessors to return the media objects filtered to where the type is "book". Sketch has an example of how to do this.

Cut, paste and modify for all the other peer types to Book. Cut and paste code can be distasteful, but if you only have a few this gets you working code that you can ship while you come up with a better solution.

Solution 2:

Write a more generic scripting KVC container that can takes advantage of the ...inPropertyWithKey: KVC methods, as well as -valueForUndefinedKey:.

In my case, my containers are immutable (in the traditional KVC sense) so I only had to worry about the latter.

When the key comes in, I look at the key and see if it is one for which there is a pre-configured rule which says "books" can be derived from "media" using this filter rule, and if there is, I do it, otherwise message super.

There is also caching going on to improve access time, observation to invalidate the caches. And I still haven't implemented the replace, insert, and remove methods.

It is a possible generic solution to this problem. The cut and paste solution is probably uglier, but may get you to working code faster. (At the expense of that ugliness, and having to modify the container for each new type introduced.)

Jim

 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Applescript-implementors mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/applescript-implementors/email@hidden

This email sent to email@hidden

References: 
 >Re: AppleScript-Cocoa Impedance Mismatch (From: Major Domo <email@hidden>)
 >Re: AppleScript-Cocoa Impedance Mismatch (From: Jim Correia <email@hidden>)
 >Re: AppleScript-Cocoa Impedance Mismatch (From: Major Domo <email@hidden>)



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.