4 <p>A class is a data type that can contain fields, constants, methods, properties, and signals. Class types support inheritance, a mechanism whereby a derived class can extend and specialize a base class.</p>
5 <section id="declaration">
6 <h>Class declarations</h>
7 <p>The simplest class declaration looks like this:</p>
12 <p>As class types support inheritance, you can specify a base class you want to derive from:</p>
14 class ClassName : BaseClassName {
19 <p>It's recommended that you derive all your classes directly or indirectly from GLib.Object, unless you have a strong reason not to. Some class features are not supported for classes not deriving from GLib.Object.</p>
21 <p>Classes cannot have multiple base classes, however they may implement multiple interfaces:</p>
23 class ClassName : BaseClassName, FirstInterfaceName, SecondInterfaceName {
26 <p>You may optionally specify an accessibility modifier. Classes support <code>public</code> and <code>private</code> accessibility and default to private if you don't specify one. Public classes may be accessed from outside the library or application they are defined in.</p>
28 public class ClassName {
31 <p>The <code>abstract</code> modifier may be placed between the optional accessibility modifier and the class name to define an abstract class. An abstract class cannot be instantiated and is used as a base class for derived classes.</p>
33 abstract class ClassName {
36 <p>The <code>static</code> modifier may be placed between the optional accessibility modifier and the class name to define a static class. A static class cannot be instantiated and may not have a base class. It can also not be used as a base class for derived classes and may only contain static members. Static classes are implicitly abstract, you may not use both modifiers, <code>abstract</code> and <code>static</code>, in the same class declaration.</p>
38 static class ClassName {
41 <p>You may optionally prefix the class name with a namespace name. This places the class in the specified namespace without the need for a separate namespace declaration.</p>
43 class NamespaceName.ClassName {
51 <section id="methods">
55 <section id="properties">
59 [ access-modifier ] [ member-modifiers ] type identifier <l>{</l> accessor-declarations [ default-value ] <l>}</l> <l>;</l>
61 accessor-declarations:
62 get-accessor [ set-accessor ]
63 set-accessor [ get-accessor ]
66 [ access-modifier ] <l>get</l> <l>;</l>
67 [ access-modifier ] <l>get</l> <l>{</l> statement-list <l>}</l>
70 [ access-modifier ] <l>set</l> [ <l>construct</l> ] <l>;</l>
71 [ access-modifier ] <l>set</l> [ <l>construct</l> ] <l>{</l> statement-list <l>}</l>
74 <l>default =</l> expression <l>;</l>
77 <section id="signals">
79 <p>The signal system allows objects to emit signals that can be handled by user-provided signal handlers.</p>
82 [ access-modifier ] <l>signal</l> return-type identifier <l>(</l> [ parameter-list ] <l>)</l> <l>;</l>