Vala Programming/Concepts/Objects

From Wikibooks, open books for an open world
Jump to navigation Jump to search

 Vala Programming 

Concepts

Basic - Objects - Variables - Memory Management - Error Handling - Introduction to DBus

Object Oriented Programming[edit | edit source]

The Vala OO System is very similar to, and is somewhat based on languages like C# and Java. Please note that unlike these languages, Vala does not force you to adopt and Object Oriented Paradigm, but it is highly recommended for maximum productivity; and because most third-party libraries and bindings use Object-Orientation, it will ultimately have to be adopted by you.

Classes[edit | edit source]

Generally Classes in Vala are declared like this:

/*Simple Class Derived From GLib.Object*/
public class Sample : GLib.Object {
    
    /*Class Fields*/    
    bool my_field; 
    int my_int_field = 2;

    public Sample () {
        /* Constructor */
    }
    public ~Sample () {
        /* Destructor */
    }
    public void my_method () {
        /*Method Code*/
    }
    public int return_method () {
        /*Return Some Integer*/
        return my_int_field;
    }
    public void param_method (int param) {
        /*Use Arguments*/
    }
}
/*Intermediate Hacking...*/

Note that if you declare a base class, it is recommended to derive it from the GLib.Object, otherwise you will not be able to access some of its features.

Polymorphism[edit | edit source]

Inheritance[edit | edit source]

Inheritance in Vala is very similar to C#. Vala supports single inheritance only, i.e you cannot inherit an object from more than one base class. The general format is:

/*Inheriting From Other Classes*/
public class Base : GLib.Object {
    public int member;
    public Base (int carg) {
        /*Code Here*/
    }
}
public class Derived : Base {
    public Derived () {
        base (14); // Call base constructor
        /*Code Here*/
    }
}

Interfaces[edit | edit source]

Construction[edit | edit source]

Abstract Classes[edit | edit source]

Properties[edit | edit source]

Functions[edit | edit source]

Overriding[edit | edit source]

Delegates[edit | edit source]

Signals[edit | edit source]

Handlers[edit | edit source]