From 35aa1410e2becb5d768b9c5142e069b4d0fc46df Mon Sep 17 00:00:00 2001 From: Milo Gilad Date: Fri, 25 Aug 2017 10:36:20 -0400 Subject: [PATCH] Finished basic OOP --- vala.html.markdown | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/vala.html.markdown b/vala.html.markdown index 036e873d..a65c528f 100755 --- a/vala.html.markdown +++ b/vala.html.markdown @@ -251,6 +251,25 @@ interface InterfaceDemo { // Can be used as a mixin // ... } +// Since method overloading isn't possible, you can use named constructors +// to get the same functionality. + +public class Calculator : GLib.Object { + + public Calculator() { + } + + public Calculator.with_name(string name) { + } + + public Calculator.model(string model_id, string name = "") { + this.with_name(@"$model_id $name"); // Chained constructors with "this" + } + ~Calculator() { } // Only needed if you're using manual memory management +} + +var calc1 = new Calculator.with_name("Temp"); +var calc2 = new Calculator.model("TI-84"); enum HouseSize { SMALL,