• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Is AppleScript's OOP 'prototype-based' or 'class-based'?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Is AppleScript's OOP 'prototype-based' or 'class-based'?


  • Subject: Is AppleScript's OOP 'prototype-based' or 'class-based'?
  • From: Brennan <email@hidden>
  • Date: Tue, 11 Dec 2007 10:01:30 +0100

'Inspired by that talk about properties:

I've heard it mentioned that AppleScript has a 'prototype-based' OOP
implementation (similar to javascript), rather than being 'class-based'
(like Java).

Well. It's true that you can do stuff like this:

(* Here we go...*)

script SteveJobs
 property strength : 4
 property dexterity : 99
 property magicSkill : missing value
end script

on distortReality()
 display dialog "The mere appearance of high quality increases profits."
end distortReality

set magicSkill of SteveJobs to distortReality
SteveJobs's magicSkill()

(* end script*)

...i.e. adding additional handlers to existing script objects,

Still, it's not possible to add additional handlers and properties to
script objects willy-nilly. There has to be a property declared in advance
where you can insert new stuff.

For example, we can't suddenly do something like

set stamina of SteveJobs to 25

or

set SteveJobs to SteveJobs & {stamina:25}

...as we can with records, because SteveJobs has no existing property
called stamina.

Similarly, I can't suddenly decide to add a new handler if there's no
property declared to 'hold' it.

(Or am I mistaken about that?)

That strikes me as being much more like 'class based' OOP, because the
structure must be declared in advance of any instantiation.

Or perhaps it's a kind of hybrid of the two, because while you can't add
new handlers, you can certainly replace them.

And as far as I know there's no way of changing the 'prototype' of
existing objects. All you can do is insert new objects into the
inheritance chain (by setting 'parent'), which is a different kind of
manipulation altogether. No?

In reality, of those very few people that do any OOP in AppleScript, I
dare say most define the script objects before compile time, and refrain
from inserting new handlers later. Very much a class-based approach.

Even swapping the value of 'parent' around at runtime must be a rare
activity, and AFAICT is only really used to illustrate that it can be
done.

What are your OOP habits in AppleScript?

I find that I rarely use it for shorter scripts, and almost always use it
(or end up using it) for larger scripts.

That suggest to me that yes, OOP really does help to manage complexity,
and yes, it is too much faffing around if you need to get a simple job
done quickly.

Brennan
 _______________________________________________
Do not post admin requests to the list. They will be ignored.
AppleScript-Users mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
Archives: http://lists.apple.com/archives/applescript-users

This email sent to email@hidden

  • Follow-Ups:
    • Re: Is AppleScript's OOP 'prototype-based' or 'class-based'?
      • From: Phil <email@hidden>
    • Re: Is AppleScript's OOP 'prototype-based' or 'class-based'?
      • From: Philip Aker <email@hidden>
  • Prev by Date: Re: difference between property and variable
  • Next by Date: Re: Is AppleScript's OOP 'prototype-based' or 'class-based'?
  • Previous by thread: Re: Application responses, Timeouts, Try statements, Activate - how do they really work?
  • Next by thread: Re: Is AppleScript's OOP 'prototype-based' or 'class-based'?
  • Index(es):
    • Date
    • Thread