Dylan (programming Language) - Classes

Classes

Classes in Dylan describe "slots" (data members, fields, ivars, etc.) of objects in a fashion similar to most OO languages. All access to slots are via methods, as in CLOS and Smalltalk. Default getter and setter methods are automatically generated based on the slot names. In contrast with most other OO languages, other methods applicable to the class are often defined outside of the class, and thus class definitions in Dylan typically include the definition of the storage only. For instance:

define class () slot title :: = "untitled", init-keyword: title:; slot position :: , required-init-keyword: position:; end class;

In this example the class "" is defined. The syntax is convention only, to make the class names stand out—the angle brackets are merely part of the class name. In comparison, in some languages the convention is to capitalize the first letter of the class name or to prefix the name with a "C" or "T" (for example). inherits from a single class, , and contains two slots, title holding a string for the window title, and position holding an X-Y point for a corner of the window. In this particular example the title has been given a default value, while the position has not. The optional "init-keyword" syntax allows the programmer to specify the initial value of the slot when instantiating an object of the class.

In languages such as C++ or Java, the class would also define its interface. In this case the definition above has no explicit instructions, so in both languages access to the slots and methods is considered protected, meaning they can be used only by subclasses. In order to allow unrelated code to use the window instances, they would have to be declared public.

In Dylan these sorts of visibility rules are not considered part of the code itself, but of the module/interface system. This adds considerable flexibility. For instance, one interface used during early development could declare everything public, whereas one used in testing and deployment could limit this. With C++ or Java these changes would require changes to the source code itself, so people won't do it, whereas in Dylan this is a completely unrelated concept.

Although this example does not use it, Dylan also supports multiple inheritance.

Read more about this topic:  Dylan (programming Language)

Famous quotes containing the word classes:

    There are two classes of men called poets. The one cultivates life, the other art,... one satisfies hunger, the other gratifies the palate.
    Henry David Thoreau (1817–1862)

    There were three classes of inhabitants who either frequent or inhabit the country which we had now entered: first, the loggers, who, for a part of the year, the winter and spring, are far the most numerous, but in the summer, except for a few explorers for timber, completely desert it; second, the few settlers I have named, the only permanent inhabitants, who live on the verge of it, and help raise supplies for the former; third, the hunters, mostly Indians, who range over it in their season.
    Henry David Thoreau (1817–1862)

    By his very success in inventing labor-saving devices, modern man has manufactured an abyss of boredom that only the privileged classes in earlier civilizations have ever fathomed.
    Lewis Mumford (1895–1990)