Page 1 of 1

Class

PostPosted: Fri Jul 25, 2008 1:28 pm
by relez
Is it possibile in Cobra Lang to re-open and modify a class? This is an easy task using Ruby and is a bit more difficult but still possible with Python.
I apologize if this is a silly question but i'm not "deep" in Cobra, today :cry:

Re: Class

PostPosted: Fri Jul 25, 2008 1:53 pm
by Charles
You can extend a class like so:
Code: Select all
extend Object

    def sayHello
        print 'hello'

This is purely a compile-time phenomena, but it works pretty well.

Cobra uses the .NET/CLR class system which has some advantages including speed and the ability to push a Cobra library out to C# and VB users. However, this system is less flexible than Ruby and Python.

Re: Class

PostPosted: Fri Jul 25, 2008 2:38 pm
by relez
Nice.
I have another questions that raises from this:
Cobra has multiple inheritance of interfaces, but it would also benefit from multiple inheritance of code.

I realize that Cobra support interfaces, so like Java, C# and others and doesn't support multiple inheritance from classes, right?

Tk u ;)

Re: Class

PostPosted: Fri Jul 25, 2008 10:25 pm
by hopscc
right Cobra (like C# and Java) only provides single inheritance.

Re: Class

PostPosted: Sat Jul 26, 2008 7:12 pm
by Charles
Currently, Cobra does not support multiple inheritance because it embraces the same OO constructs seen in C# and Java. As with C#, you can get around this to some extent by using extend on interfaces which themselves permit multiple inheritance:
Code: Select all
extend IShape
    def move(dx as int, dy as int)
        .x += dx
        .y += dy

But I would still like to address this shortcoming in the future. At least one person has suggested that "traits" are the way to go and I'll be taking a look at those.

I won't get to this for awhile as it will require some deep reading and consideration, and I don't want it to block many smaller things that are coming down the pipe.

-Chuck