Object specific behavior?

  • Long time ago I use to make simple programs using HyperCard. IMHO this is
    the simplest programming environment ever created. There were some things I
    was accustomed to and that I looked for in Cocoa.
    Let's say I want to create a simple application with just one button. When
    the user clicks on the button a beep should be heard.
    In HyperCard (and in Macromedia Director) each object has attributes which
    you can configure with an inspector. One of the attributes is a script
    window where you can add object specific code. For instance to make the
    button beep you would write

    on mouseUp
      beep()
    end mouseUp

    Now when we look at Cocoa there is an inspector where you can change
    attributes of the button, but not the code (of the button instance). Instead
    I'm forced to create an extra object called AppController or something
    similar and I'm forced to use target action mechanism. And this just beacuse
    all code is in the class while the data (ivars) is in the objects.
    This division between data and code seems somewhat arbitrary. We know from
    such languages as Lisp that there is real difference between data and code;
    that is if the language implementors do not force it on us.
    What I'm saying is that Cocoa could be simpler to use if you could attach
    code as one attribute to your objects. I'm not Cocoa savvy, but this seems
    reasonable.
    Maybe I'm missing something. Is there a simple way to create a beep without
    creating a new class?

    Any thoughts on this?
  • On Oct 25, 2007, at 4:00 AM, Frank Bettger wrote:

    > What I'm saying is that Cocoa could be simpler to use if you could
    > attach
    > code as one attribute to your objects. I'm not Cocoa savvy, but this
    > seems
    > reasonable.

    Perhaps, but this kind of advocacy isn't really appropriate here.

    >
    > Maybe I'm missing something. Is there a simple way to create a beep
    > without
    > creating a new class?

    Nope.  Someone would have to write the code, and make a palette. (The
    discussion of writing that code would be appropriate here.. :-)
  • Cocoa ubiquitously uses the Model-View-Controller design pattern to organize the roles of collaborating objects within an application.
      In the specific instance cited, the role of a button is to receive user input and provide feedback to the user.  Button’s do not beep.  Instead, buttons send messages to other objects that implement application specific behavior such as beeping.  This separation of roles has numerous benefits.  First, the button class is reusable largely because it is not application specific.  Second, the generic ability to send almost any message in response to user input reduces the number of times button has to be subclassed to nearly zero. Third, when the application behavior is more complex than just beeping, the flexibility to send messages to anonymous receivers that may be determined at run-time by the current application state and user selections etc. becomes extremely powerful and flexible.
    Naively adding scripts to be performed when a user clicks a button is (in larger applications) fragile and leads to spaghetti code.  There are advantages to extremely rapid specification of behavior.  A system like pyObjC or Ruby or F-Script might be exactly what you are looking for.  I highly recommend http://www.fscript.org/.  Each of these combinations of scripting and Cocoa enable (more) rapid development without sacrificing the benefits of Cocoa’s design.
  • On 25.10.2007, at 10:00, Frank Bettger wrote:
    > Maybe I'm missing something. Is there a simple way to create a beep
    > without
    > creating a new class?

      Read Cocoa's docs on the "Model-View-Controller" pattern. The most
    basic design idea behind Cocoa is this pattern, and as the name says
    it encourages strict separation of the model (i.e. actual data
    storage) the view (i.e. button's, windows, menus) and the controller
    (the actual code that does the work).

    Cheers,
    -- M. Uli Kusterer
    http://www.zathras.de
  • On Oct 25, 2007, at 3:00 AM, Frank Bettger wrote:

    > Long time ago I use to make simple programs using HyperCard. IMHO
    > this is
    > the simplest programming environment ever created. There were some
    > things I
    > was accustomed to and that I looked for in Cocoa.
    > Let's say I want to create a simple application with just one
    > button. When
    > the user clicks on the button a beep should be heard.
    > In HyperCard (and in Macromedia Director) each object has
    > attributes which
    > you can configure with an inspector. One of the attributes is a script
    > window where you can add object specific code. For instance to make
    > the
    > button beep you would write
    >
    > on mouseUp
    > beep()
    > end mouseUp

    It sounds like you want to investigate AppleScript Studio then (which
    is, of course, a different mailing list).

    Glenn Andreas                      <gandreas...>
      <http://www.gandreas.com/> wicked fun!
    quadrium | flame : flame fractals & strange attractors : build,
    mutate, evolve, animate
previous month october 2007 next month
MTWTFSS
1 2 3 4 5 6 7
8 9 10 11 12 13 14
15 16 17 18 19 20 21
22 23 24 25 26 27 28
29 30 31        
Go to today