Re: [Vala] run the metho1 from the method2 of class2



On Wed, Sep 12, 2012 at 2:28 AM, Jonas Kulla <nyocurio gmail com> wrote:
2012/9/11 "Luis L. Rodríguez Oro" <luisr uci cu>

Hi all, please help me.
...

in Clas2, then pass the "this" reference when you create your main_window
object.
Then you can call any public method on it from Clas2.


or if you don't want any reference of the main_window class inside the
class2 (loosing coupling) you can use a signal to implement a sort of
observer pattern [1].

class Clas2 {
    public signal void update_interface (args...);

    private void method2 (args...) {
        update_interface (args....);
    }
}

and on the main_window class you subscribe to the signal and then call method2:

class main_window:... {
    public Clas2 cl;

    public main_window () {
        cl = new Clas2 ();
        cl.update_interface.connect ((args...) => { method1 (); })
    }

    public void method1 () {
       ....
    }
}

HTH,
Andrea

[1] http://en.wikipedia.org/wiki/Observer_pattern



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]