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
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:
“Whats the greatest enemy of Christianity to-day? Frozen meat. In the past only members of the upper classes were thoroughly sceptical, despairing, negative. Why? Among other reasons, because they were the only people who could afford to eat too much meat. Now theres cheap Canterbury lamb and Argentine chilled beef. Even the poor can afford to poison themselves into complete scepticism and despair.”
—Aldous Huxley (18941963)
“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 (18171862)
“Of all classes the rich are the most noticed and the least studied.”
—John Kenneth Galbraith (b. 1908)