summaryrefslogtreecommitdiffhomepage
path: root/vala.html.markdown
diff options
context:
space:
mode:
authorMilo Gilad <milogaccnts@gmail.com>2017-08-25 13:24:01 -0400
committerMilo Gilad <milogaccnts@gmail.com>2017-08-25 13:24:01 -0400
commita6359357fdc0cec3731a5f3088bb8d590b9cc744 (patch)
treeba71b4757f8d7d1c5b9af3960e74fa026f3eed7a /vala.html.markdown
parentbf7ed153ee023ea2ba529ccf4ee486b1a59a183a (diff)
Added section on abstract classes/methods
Diffstat (limited to 'vala.html.markdown')
-rwxr-xr-xvala.html.markdown28
1 files changed, 28 insertions, 0 deletions
diff --git a/vala.html.markdown b/vala.html.markdown
index 11165aa4..3103f9c5 100755
--- a/vala.html.markdown
+++ b/vala.html.markdown
@@ -353,6 +353,34 @@ class SubDemo : SuperDemo {
}
}
+// Abstract Classes and Methods
+
+public abstract class OperatingSystem : GLib.Object {
+ public void turn_on() {
+ stdout.printf("Booted successfully.\n");
+ }
+ public abstract void use_computer();
+}
+
+public class Ubuntu : OperatingSystem {
+ public override void use_computer() { // Abstract methods must be overridden
+ stdout.printf("Beep boop\n");
+ }
+}
+
+// Add default behavior to an abstract method by making it "virtual".
+
+public abstract class HardDrive : GLib.Object {
+ public virtual void die() {
+ stdout.printf("CLICK-CLICK-CLICK\n");
+ }
+}
+public class MyHD : HardDrive {
+ public override void die() {
+ return;
+ }
+}
+
```
* More Vala documentation can be found [here](https://valadoc.org/).
* Read about building GUIs with GTK+ and Vala [here](http://archive.is/7C7bw).