Re: [Vala] Delegate that returns its own type
- From: Frederik <scumm_fredo gmx net>
- To: vala-list gnome org
- Subject: Re: [Vala] Delegate that returns its own type
- Date: Fri, 23 May 2008 12:18:28 +0200
Zsolt Börcsök schrieb:
If not, do you have any suggestion to replace this kind of declaration.
As a workaround you could code your own delegates with the classic
strategy pattern:
-------------
using GLib;
private interface MyDelegate {
public abstract MyDelegate call ();
}
private class MyDelegateImpl : Object, MyDelegate {
public MyDelegate call () {
return new MyDelegateImpl ();
}
}
public class DelegateTest {
private static void wants_delegate (MyDelegate deleg) {
MyDelegate result = deleg.call ();
}
public static int main (string[] args) {
MyDelegate deleg1 = new MyDelegateImpl ();
MyDelegate deleg2 = deleg1.call ();
wants_delegate (deleg2);
return 0;
}
}
-------------
The delegate implementations have to be outside since Vala doesn't seem
to support anonymous inner classes like Java.
Regards,
Frederik
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]