Carapace

Object Example: a Trumpet

The following is an example of a Carapace object. This Trumpet object describes a trumpet (ie. the musical instrument) which can be muted (ie. have a mute stuffed in the end to change the sound) or open (no mute).

(class "Trumpet"

    (interface

        (properties

            (mute String)
            (metal String readOnly)
        )

        (methods

            # constructor function - used when creating a Trumpet
            (NIL Trumpet ( (m String) ) )

            # play a piece of music
            (NIL play ( (m Music) ) )
        )
    )
)
Points to note:

An Additional Interface

Our Trumpet object is pretty good - it can already play music - but suppose the people living in the same house wanted some sort of control over the trumpet. These people don't want to play the trumpet - they just want to control its volume. This could be done by having an additional interface on our Trumpet object eg.:

    (interface

        (methods

            # set the maximum volume
            (NIL setVolume ( (max Integer) ) )

            # make it silent!
            (NIL silencer () )
        )
    )
Putting it all together, the full class declaration looks like:
(class "Trumpet"

    (interface

        (properties

            (mute String)
            (metal String readOnly)
        )

        (methods

            # initialise the object
            (NIL Trumpet ( (m String) ) )

            # play a piece of music
            (NIL play ( (m String) ) )
        )
    )

    (interface Volume

        (methods

            # set the maximum volume
            (NIL setVolume ( (max Integer) ) )

            # make it silent!
            (NIL silencer () )
        )
    )
)
To see how to create and access a Trumpet object, click here.

For a complete description of object definition, click here

Accessing a Trumpet via COM

By adding a few more details to our Trumpet example above, we can access it from COM.

To see what is required, click here.


Contents Index Current topic: objects Related topics: functions