• 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
Re: OO Theory misconceptions (was Re: can I make a list of
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: OO Theory misconceptions (was Re: can I make a list of


  • Subject: Re: OO Theory misconceptions (was Re: can I make a list of
  • From: Nigel Garvey <email@hidden>
  • Date: Thu, 31 Jan 2002 13:10:26 +0000

email@hidden wrote on Thu, 31 Jan 2002 00:02:31 -0500:

> on makeSillyObject from initialValue
> script
> property v : initialValue
> to display()
> display dialog "The silly value is " & v
> end display
> to double()
> return "Make mine a double"
> end double
> end script
> end makeSillyObject
>
> on makeSillyString from initialValue
> script
> property parent : makeSillyObject from initialValue
> to double()
> return my v & my v
> end double
> end script
> end makeSillyString
>
> on makeSillyNumber from initialValue
> script
> property parent : makeSillyObject from initialValue
> to double()
> return 2 * my v
> end double
> to root()
> return sqrt(my v)
> end root
> end script
> end makeSillyNumber

I can imagine Arthur having fun with this syntax: ;-)

> makeSillyObject from {4,2} returning sO
> makeSillyString from "Hi" returning sS
> makeSillyNumber from 37 returning sN
>
> tell sO to display()
> tell sS to display()
> tell sN to display()
>
> {double() of sO, double() of sS, double() of sN, root() of sN}
> --> Result: {"Make mine a double!", "HiHi", 84, 6.480740698408}

Allowing for the fact that there's no sqrt() function provided, this
result depends on makeSillyNumber having been called with a parameter of
42.

>But now you only get one of each object, and each child has to provide the
>place
>for the property v, even though all children will use it. (You could put v
>in
>the parent, but then you'd have to have initialization code in the parent
>and
>through all the children to set up the initial value at run time.)
>
>So, while the "constructor function" approach is oddly inside-out, its what
>I
>use all the time. I usually won't go to the trouble of defining an object
>and
>then only making one of it--its like defining a function and then only
>calling
>it once.

Well, that just about knocks it on the head for modular, "easily
maintainable" code.... ;-)

NG


  • Follow-Ups:
    • Re: OO Theory misconceptions (was Re: can I make a list of
      • From: email@hidden (Michael Sullivan)
  • Prev by Date: Null?
  • Next by Date: Alias Behavior When Scripting...
  • Previous by thread: Re: OO Theory misconceptions (was Re: can I make a list of
  • Next by thread: Re: OO Theory misconceptions (was Re: can I make a list of
  • Index(es):
    • Date
    • Thread