diff options
author | Milo Gilad <milogaccnts@gmail.com> | 2017-08-25 10:36:20 -0400 |
---|---|---|
committer | Milo Gilad <milogaccnts@gmail.com> | 2017-08-25 10:36:20 -0400 |
commit | 35aa1410e2becb5d768b9c5142e069b4d0fc46df (patch) | |
tree | 875b7ae538d8fd0f331c3cd361921d9ba24dd2b9 /vala.html.markdown | |
parent | a6c3a64a4c897a1f7e7acfbfe6318866317770ad (diff) |
Finished basic OOP
Diffstat (limited to 'vala.html.markdown')
-rwxr-xr-x | vala.html.markdown | 19 |
1 files changed, 19 insertions, 0 deletions
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, |