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
Forums
Class
5 posts
• Page 1 of 1
Re: Class
You can extend a class like so:
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.
- 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.
- Charles
- Posts: 2515
- Location: Los Angeles, CA
Re: Class
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
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
- relez
- Posts: 69
Re: Class
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:
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
- 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
- Charles
- Posts: 2515
- Location: Los Angeles, CA
5 posts
• Page 1 of 1
Who is online
Users browsing this forum: No registered users and 15 guests