Re: [Vala] Is there any way to access generic type from the interface?

2016-02-28 Thread Felipe Lavratti
I see interfaces with default implementation as a anti-pattern, actually. I
don't use it. Also, IMHO mixins are good for utility code, other than that
it might smell.

Maybe vala should have a literal mixin, with only virtual methods and not
instantiable nor castable. Only useful to add utility methods into classes.
On Sun, Feb 28, 2016 at 22:50 Daniel Espinosa  wrote:

> If you want your interface to provide, not just default implementations,
> but methods your classes should not need to implement they self, use
> virtual methods, you can provide an implementation for this method your
> derived classes don't need to implement but inherited. Static methods can
> be used to be reused if you want.
> El feb. 28, 2016 4:31 PM, "Felipe Lavratti" 
> escribió:
>
>> Even better, try this main instead the previous:
>>
>> int main () {
>>
>> IMixinInterface fooer = new NothingSpecialFooer();
>> fooer.foo();
>>
>> fooer = new TheSpecialFooer();
>> fooer.foo();
>>
>> return 0;
>> }
>>
>> Here we use the interface as the type of the object to show
>> polymorphism with mixin happening.
>>
>> It prints:
>>
>> $ ./test
>> ** Message: test.vala:5: fooed defaulty!
>> ** Message: test.vala:13: dummy string
>> ** Message: test.vala:22: fooed specially!
>>
>>
>>
>> On Sun, Feb 28, 2016 at 7:24 PM, Felipe Lavratti 
>> wrote:
>> > Right, I see what u are asking now.
>> >
>> > Well, if you want to do Mixins in Vala, you'll have to do the "static"
>> > workaround, since it doesn't support by default:
>> >
>> https://wiki.gnome.org/Projects/Vala/Tutorial#Mixins_and_Multiple_Inheritanae
>> >
>> > Now you want to do Mixing with Generics? Ok, add the generic argument to
>> > each  Mixin method of your interface:
>> >
>> > public interface IMixinInterface : Object {
>> > public abstract void foo();
>> >
>> > public static T default_fooing(T arg) {
>> > GLib.message("fooed defaulty!");
>> > return arg;
>> > }
>> > }
>> >
>> > public abstract class BaseFooer : Object, IMixinInterface {
>> > public virtual void foo() {
>> > var dummy_string = IMixinInterface.default_fooing("dummy
>> > string");
>> > GLib.message(dummy_string);
>> > }
>> > }
>> >
>> > public class NothingSpecialFooer : BaseFooer {
>> > }
>> >
>> > public class TheSpecialFooer : BaseFooer {
>> > public override void foo() {
>> > GLib.message("fooed specially!");
>> > }
>> > }
>> >
>> > int main () {
>> >
>> > var fooer = new NothingSpecialFooer();
>> > fooer.foo();
>> >
>> > var fooer2 = new TheSpecialFooer();
>> > fooer2.foo();
>> >
>> > return 0;
>> > }
>> >
>> >
>> > This example doesn't cover BaseFooer taking a generic argument, if the
>> > example is not enough, please provide me more details about how is the
>> > generic argument used in BaseFooer.
>> >
>> > - Fanl
>> >
>> >
>>
>>
>>
>> --
>> Skype: felipeanl
>>
>
___
vala-list mailing list
vala-list@gnome.org
https://mail.gnome.org/mailman/listinfo/vala-list


Re: [Vala] Is there any way to access generic type from the interface?

2016-02-28 Thread Daniel Espinosa
If you want your interface to provide, not just default implementations,
but methods your classes should not need to implement they self, use
virtual methods, you can provide an implementation for this method your
derived classes don't need to implement but inherited. Static methods can
be used to be reused if you want.
El feb. 28, 2016 4:31 PM, "Felipe Lavratti"  escribió:

> Even better, try this main instead the previous:
>
> int main () {
>
> IMixinInterface fooer = new NothingSpecialFooer();
> fooer.foo();
>
> fooer = new TheSpecialFooer();
> fooer.foo();
>
> return 0;
> }
>
> Here we use the interface as the type of the object to show
> polymorphism with mixin happening.
>
> It prints:
>
> $ ./test
> ** Message: test.vala:5: fooed defaulty!
> ** Message: test.vala:13: dummy string
> ** Message: test.vala:22: fooed specially!
>
>
>
> On Sun, Feb 28, 2016 at 7:24 PM, Felipe Lavratti 
> wrote:
> > Right, I see what u are asking now.
> >
> > Well, if you want to do Mixins in Vala, you'll have to do the "static"
> > workaround, since it doesn't support by default:
> >
> https://wiki.gnome.org/Projects/Vala/Tutorial#Mixins_and_Multiple_Inheritanae
> >
> > Now you want to do Mixing with Generics? Ok, add the generic argument to
> > each  Mixin method of your interface:
> >
> > public interface IMixinInterface : Object {
> > public abstract void foo();
> >
> > public static T default_fooing(T arg) {
> > GLib.message("fooed defaulty!");
> > return arg;
> > }
> > }
> >
> > public abstract class BaseFooer : Object, IMixinInterface {
> > public virtual void foo() {
> > var dummy_string = IMixinInterface.default_fooing("dummy
> > string");
> > GLib.message(dummy_string);
> > }
> > }
> >
> > public class NothingSpecialFooer : BaseFooer {
> > }
> >
> > public class TheSpecialFooer : BaseFooer {
> > public override void foo() {
> > GLib.message("fooed specially!");
> > }
> > }
> >
> > int main () {
> >
> > var fooer = new NothingSpecialFooer();
> > fooer.foo();
> >
> > var fooer2 = new TheSpecialFooer();
> > fooer2.foo();
> >
> > return 0;
> > }
> >
> >
> > This example doesn't cover BaseFooer taking a generic argument, if the
> > example is not enough, please provide me more details about how is the
> > generic argument used in BaseFooer.
> >
> > - Fanl
> >
> >
>
>
>
> --
> Skype: felipeanl
>
___
vala-list mailing list
vala-list@gnome.org
https://mail.gnome.org/mailman/listinfo/vala-list


Re: [Vala] Is there any way to access generic type from the interface?

2016-02-28 Thread Felipe Lavratti
Even better, try this main instead the previous:

int main () {

IMixinInterface fooer = new NothingSpecialFooer();
fooer.foo();

fooer = new TheSpecialFooer();
fooer.foo();

return 0;
}

Here we use the interface as the type of the object to show
polymorphism with mixin happening.

It prints:

$ ./test
** Message: test.vala:5: fooed defaulty!
** Message: test.vala:13: dummy string
** Message: test.vala:22: fooed specially!



On Sun, Feb 28, 2016 at 7:24 PM, Felipe Lavratti  wrote:
> Right, I see what u are asking now.
>
> Well, if you want to do Mixins in Vala, you'll have to do the "static"
> workaround, since it doesn't support by default:
> https://wiki.gnome.org/Projects/Vala/Tutorial#Mixins_and_Multiple_Inheritanae
>
> Now you want to do Mixing with Generics? Ok, add the generic argument to
> each  Mixin method of your interface:
>
> public interface IMixinInterface : Object {
> public abstract void foo();
>
> public static T default_fooing(T arg) {
> GLib.message("fooed defaulty!");
> return arg;
> }
> }
>
> public abstract class BaseFooer : Object, IMixinInterface {
> public virtual void foo() {
> var dummy_string = IMixinInterface.default_fooing("dummy
> string");
> GLib.message(dummy_string);
> }
> }
>
> public class NothingSpecialFooer : BaseFooer {
> }
>
> public class TheSpecialFooer : BaseFooer {
> public override void foo() {
> GLib.message("fooed specially!");
> }
> }
>
> int main () {
>
> var fooer = new NothingSpecialFooer();
> fooer.foo();
>
> var fooer2 = new TheSpecialFooer();
> fooer2.foo();
>
> return 0;
> }
>
>
> This example doesn't cover BaseFooer taking a generic argument, if the
> example is not enough, please provide me more details about how is the
> generic argument used in BaseFooer.
>
> - Fanl
>
>



-- 
Skype: felipeanl
___
vala-list mailing list
vala-list@gnome.org
https://mail.gnome.org/mailman/listinfo/vala-list


Re: [Vala] Is there any way to access generic type from the interface?

2016-02-28 Thread Felipe Lavratti
​​
Right, I see what u are asking now.

Well, if you want to do Mixins in Vala, you'll have to do the "static"
workaround, since it doesn't support by default:
https://wiki.gnome.org/Projects/Vala/Tutorial#Mixins_and_Multiple_Inheritanae

Now you want to do Mixing with Generics? Ok, add the generic argument to
each  Mixin method of your interface:

​public interface IMixinInterface : Object {
public abstract void foo();

public static T default_fooing(T arg) {
GLib.message("fooed defaulty!");
return arg;
}
}

public abstract class BaseFooer : Object, IMixinInterface {
public virtual void foo() {
var dummy_string = IMixinInterface.default_fooing("dummy
string");
GLib.message(dummy_string);
}
}

public class NothingSpecialFooer : BaseFooer {
}

public class TheSpecialFooer : BaseFooer {
public override void foo() {
GLib.message("fooed specially!");
}
}

int main () {

var fooer = new NothingSpecialFooer();
fooer.foo();

var fooer2 = new TheSpecialFooer();
fooer2.foo();

return 0;
}​


​This example doesn't cover BaseFooer taking a generic argument, if the
example is not enough, please​ provide me more details about how is the
generic argument used in BaseFooer.

- Fanl
___
vala-list mailing list
vala-list@gnome.org
https://mail.gnome.org/mailman/listinfo/vala-list


Re: [Vala] Is there any way to access generic type from the interface?

2016-02-28 Thread mar...@saepia.net
Hello,

of course I made mistake in my code.

I want to do interface that acts as a mixin, which will be mixed into class
specifies generic type, and I want methods from this mixin return the same
type as class that embeds the mixin.

Now I create interface with generic type, so in the parent class I have to
write

public class MyClass : MyBaseClass, MyInterface {

}

but it's kind of redundant. I would like to write

public class MyClass : MyBaseClass, MyInterface {

}

and access from MyInterface information that SomeType was passed to
MyBaseClass as generic type.

Is it possible at all?

m.

2016-02-28 2:12 GMT+01:00 Felipe Lavratti :

> Hey Marcin,
>
> What is exactly you need from interfaces in your code ?Are you doing
> Dependency Inversion?
>
> Felipe
>
>
> On Sat, Feb 27, 2016 at 4:40 PM Daniel Espinosa  wrote:
>
>> Is not valid code. Interfaces should "derive" from Object. Interfaces
>> list dependencies, the first one should be Object, then other interfaces
>> depends on, the order matters, because if other interfaces depends on same,
>> they should be added first.
>>
>> For your question, use typeof(G)
>> El feb. 27, 2016 1:26 PM, "Felipe Lavratti" 
>> escribió:
>>
>>> I don't know if your code is valid Vala. MyInterface should not inherit
>>> MyClass.
>>>
>>> On Sat, Feb 27, 2016 at 10:59 mar...@saepia.net 
>>> wrote:
>>>
>>> > Hello,
>>> >
>>> > I am planning to use interfaces as in vspec as they are nice syntax
>>> sugar
>>> > for my purpose.
>>> >
>>> > However, in order to make it working properly, I need to access type
>>> > defined as generic in the parent class implementing interface.
>>> Something
>>> > like
>>> >
>>> > public interface MyIface : MyClass {
>>> >   public MyGenericType something() {
>>> > ...
>>> >   }
>>> > }
>>> >
>>> >
>>> > public abstract class MyClass : MyIface {
>>> >
>>> > }
>>> >
>>> >
>>> > Is it possible in any way?
>>> >
>>> > m.
>>> > ___
>>> > vala-list mailing list
>>> > vala-list@gnome.org
>>> > https://mail.gnome.org/mailman/listinfo/vala-list
>>> >
>>> ___
>>> vala-list mailing list
>>> vala-list@gnome.org
>>> https://mail.gnome.org/mailman/listinfo/vala-list
>>>
>>
___
vala-list mailing list
vala-list@gnome.org
https://mail.gnome.org/mailman/listinfo/vala-list


Re: [Vala] Is there any way to access generic type from the interface?

2016-02-27 Thread Daniel Espinosa
Is not valid code. Interfaces should "derive" from Object. Interfaces list
dependencies, the first one should be Object, then other interfaces depends
on, the order matters, because if other interfaces depends on same, they
should be added first.

For your question, use typeof(G)
El feb. 27, 2016 1:26 PM, "Felipe Lavratti"  escribió:

> I don't know if your code is valid Vala. MyInterface should not inherit
> MyClass.
>
> On Sat, Feb 27, 2016 at 10:59 mar...@saepia.net  wrote:
>
> > Hello,
> >
> > I am planning to use interfaces as in vspec as they are nice syntax sugar
> > for my purpose.
> >
> > However, in order to make it working properly, I need to access type
> > defined as generic in the parent class implementing interface. Something
> > like
> >
> > public interface MyIface : MyClass {
> >   public MyGenericType something() {
> > ...
> >   }
> > }
> >
> >
> > public abstract class MyClass : MyIface {
> >
> > }
> >
> >
> > Is it possible in any way?
> >
> > m.
> > ___
> > vala-list mailing list
> > vala-list@gnome.org
> > https://mail.gnome.org/mailman/listinfo/vala-list
> >
> ___
> vala-list mailing list
> vala-list@gnome.org
> https://mail.gnome.org/mailman/listinfo/vala-list
>
___
vala-list mailing list
vala-list@gnome.org
https://mail.gnome.org/mailman/listinfo/vala-list


Re: [Vala] Is there any way to access generic type from the interface?

2016-02-27 Thread Felipe Lavratti
I don't know if your code is valid Vala. MyInterface should not inherit
MyClass.

On Sat, Feb 27, 2016 at 10:59 mar...@saepia.net  wrote:

> Hello,
>
> I am planning to use interfaces as in vspec as they are nice syntax sugar
> for my purpose.
>
> However, in order to make it working properly, I need to access type
> defined as generic in the parent class implementing interface. Something
> like
>
> public interface MyIface : MyClass {
>   public MyGenericType something() {
> ...
>   }
> }
>
>
> public abstract class MyClass : MyIface {
>
> }
>
>
> Is it possible in any way?
>
> m.
> ___
> vala-list mailing list
> vala-list@gnome.org
> https://mail.gnome.org/mailman/listinfo/vala-list
>
___
vala-list mailing list
vala-list@gnome.org
https://mail.gnome.org/mailman/listinfo/vala-list