Quarks-help: use Quark-openHelpFile
[supercollider.git] / Help / Language / Classes.html
blobf8624f9970b27db697f4d75f902b6f80d1215dcf
1 <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
2 <html>
3 <head>
4 <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
5 <meta http-equiv="Content-Style-Type" content="text/css">
6 <title></title>
7 <meta name="Generator" content="Cocoa HTML Writer">
8 <meta name="CocoaVersion" content="949.54">
9 <style type="text/css">
10 p.p1 {margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Helvetica}
11 p.p2 {margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Helvetica; min-height: 14.0px}
12 p.p3 {margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Helvetica}
13 p.p4 {margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Helvetica}
14 p.p5 {margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Monaco}
15 p.p6 {margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Monaco; color: #002cab}
16 p.p7 {margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Monaco; color: #872c1c}
17 p.p8 {margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Monaco; min-height: 16.0px}
18 span.s1 {color: #0024f8}
19 span.s2 {color: #002cab}
20 span.s3 {color: #000000}
21 span.Apple-tab-span {white-space:pre}
22 </style>
23 </head>
24 <body>
25 <p class="p1"><b>Classes</b></p>
26 <p class="p2"><br></p>
27 <p class="p3"><span class="Apple-tab-span"> </span>All objects in SuperCollider are members of a class that describes the objects' data and interface. The name of a class must begin with a capital letter. Class names are the only global values in the SC language. Since classes are themselves objects, the value of a class name identifier is the object representing that class.</p>
28 <p class="p2"><br></p>
29 <p class="p4"><b>Instance Variables</b></p>
30 <p class="p2"><br></p>
31 <p class="p3"><span class="Apple-tab-span"> </span>The data of an object is contained in its instance variables. Instance variables are of two kinds, named and indexed. Each object contains a separate copy of its instance variables.</p>
32 <p class="p2"><br></p>
33 <p class="p3"><span class="Apple-tab-span"> </span>Some classes' instances have no instance variables at all but instead have an atomic value. Classes whose instances consist of an atomic value are <a href="../Math/Integer.html"><span class="s1">Integer</span></a>, <a href="../Math/Float.html"><span class="s1">Float</span></a>, <a href="../Core/Symbol.html"><span class="s1">Symbol</span></a>, <a href="../Core/True.html"><span class="s1">True</span></a>, <a href="../Core/False.html"><span class="s1">False</span></a>, <a href="../Core/Nil.html"><span class="s1">Nil</span></a>, <a href="../Math/Infinitum.html"><span class="s1">Infinitum</span></a>, <a href="../Core/Char.html"><span class="s1">Char</span></a>, <a href="../GUI/GUI-Tools/Color.html"><span class="s1">Color</span></a>.</p>
34 <p class="p2"><br></p>
35 <p class="p3"><span class="Apple-tab-span"> </span>Instance variables declaration lists occur after the open curly bracket of the class definition and are preceeded by the reserved word <b>var</b>. Instance variables names in the list may be initialized to a default literal value by using an equals sign. Instance variables which are not explicitly initialized will be set to nil. Instance variables that are immutable are defined by the reserved word <b>const</b>.</p>
36 <p class="p2"><br></p>
37 <p class="p3"><span class="Apple-tab-span"> </span>Instance variables may only be directly accessed and changed from within the class' own methods. Instance variables may be exposed to clients by adding getter and setter messages to the class. A <b>getter</b> message is a message with the same name as the variable which returns the value of that variable when sent to the receiver. A <b>setter</b> message is a message with the name of the variable with an underscore appended which sets the value of the instance variable to the value of the argument to the message. Getter and setter methods may be defined in the declaration of the instance variable. A getter message for an instance variable is created by typing a less than sign &lt; before the variable name. A setter message is created by typing a greater than &gt; sign before the variable name. If both occur then they must occur in the order &lt;&gt;.</p>
38 <p class="p2"><br></p>
39 <p class="p5"><span class="s2">var</span> a, &lt;b, &gt;c, &lt;&gt;d;</p>
40 <p class="p3"><span class="Apple-tab-span"> </span>a has no getter or setter.</p>
41 <p class="p3"><span class="Apple-tab-span"> </span>b has a getter but not a setter.</p>
42 <p class="p3"><span class="Apple-tab-span"> </span>c has only a setter.</p>
43 <p class="p3"><span class="Apple-tab-span"> </span>d has both a getter and setter.</p>
44 <p class="p2"><br></p>
45 <p class="p2"><br></p>
46 <p class="p6">Point<span class="s3"> {</span></p>
47 <p class="p7"><span class="s3"><span class="Apple-tab-span"> </span></span>// x and y are instance variables which have both getter and setter methods</p>
48 <p class="p7"><span class="s3"><span class="Apple-tab-span"> </span></span>// and default to zero.</p>
49 <p class="p5"><span class="Apple-tab-span"> </span><span class="s2">var</span> &lt;&gt;x = 0, &lt;&gt;y = 0;<span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span></p>
50 <p class="p5"><span class="Apple-tab-span"> </span>...</p>
51 <p class="p5">}</p>
52 <p class="p8"><br></p>
53 <p class="p5">p = <span class="s2">Point</span>.new;</p>
54 <p class="p7"><span class="s3">p.x_(5);<span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span></span>// send setter message to set x to 5</p>
55 <p class="p7"><span class="s3">p.y_(7);<span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span></span>// send setter message to set y to 7</p>
56 <p class="p7"><span class="s3">p.x = 5;<span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span></span>// send setter message using setter assignment (See [03 Assignment])</p>
57 <p class="p7"><span class="s3">p.y = 7;<span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span></span>// send setter message using setter assignment (See [03 Assignment])</p>
58 <p class="p7"><span class="s3">a = p.x;<span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span></span>// send getter message for x</p>
59 <p class="p7"><span class="s3">b = p.y;<span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span></span>// send getter message for y</p>
60 <p class="p2"><br></p>
61 <p class="p2"><br></p>
62 <p class="p4"><b>Class Variables</b></p>
63 <p class="p2"><br></p>
64 <p class="p3"><span class="Apple-tab-span"> </span>Class variables are values that are shared by all objects in the class. Class variable declaration lists are preceeded by the reserved word <b>classvar</b> and may be interspersed with instance variable declaration lists. Class variables like instance variables may only be directly accessed by methods of the class. Class variables may also have getter and setter methods created for them using the less than &lt; and greater than &gt; symbols.</p>
65 <p class="p2"><br></p>
66 <p class="p2"><br></p>
67 <p class="p4"><b>Instance Methods</b></p>
68 <p class="p2"><br></p>
69 <p class="p3"><span class="Apple-tab-span"> </span>The messages of a class' interface are implemented in the methods of the class. When an object is sent a message the method whose name matches the message selector in the receiver's class is executed.</p>
70 <p class="p2"><br></p>
71 <p class="p3"><span class="Apple-tab-span"> </span>Method definitions follow the class variable and instance variable declarations in the class.</p>
72 <p class="p2"><br></p>
73 <p class="p3"><span class="Apple-tab-span"> </span>Method definitions are similar to FunctionDefs in syntax. Method definitions begin with the message selector. The message selector must be an identifier or a binary operator. Methods have arguments and variable declarations with the same syntax as in FunctionDefs. Methods however have an implicit first argument named <b>this</b> which is the receiver of the message. The variable 'this' may be referred to just like any of the other arguments and variables in the method. You may not assign a value to 'this'.</p>
74 <p class="p2"><br></p>
75 <p class="p2"><br></p>
76 <p class="p4"><b>Class Methods</b></p>
77 <p class="p2"><br></p>
78 <p class="p3"><span class="Apple-tab-span"> </span>Class Methods are methods that implement messages sent to the class object. A common example is the message <b>new</b> which is sent to the class object to create a new instance of the class. Class method names have an asterisk preceeding the message selector.</p>
79 <p class="p2"><span class="Apple-tab-span"> </span></p>
80 <p class="p3">See also: <a href="../Core/Kernel/Class.html"><span class="s1">Class</span></a></p>
81 <p class="p2"><br></p>
82 </body>
83 </html>