Abstracts
Monkey Forums/Monkey Programming/Abstracts
| ||
Hello All, I'm having a horrible problem with Abstract methods and classes, I have been looking through the DOCs, but my question is when assigning a Abstract do the methods need to be the same.. Example: Class Test Field x:Float Field y:Float Method Create() Abstract End Class Test2 Extends Test Method Create(x:Float, y:Float) Super.x = x Super.y = y End End Would this be correct.. I'm at work so I can't test it, I'm writing code for my new project. |
| ||
Yes, the method signature has to be the same. Otherwise they're different methods. |
| ||
So this should be a working group of code correct..?strict Import mojo 'Primary Function (Simular to Java) Function Main:Int() local m:M = new M() End Class M Extends App Public Field glist:List<GO> = new List<GO> Method OnCreate:Int() Local player:P = New P player.Create(x,y) player.addlast(glist) local enemy:E = New E enemy.Create(x,y) enemy.addlist(glist) Return(0) End Method OnUpdate:Int() Return(0) End Method OnRender:Int() Return(0) End End Class GO Abstract Public Field x:Float Public Field y:Float Method Create(x:Float, y:Float) Abstract End Class Class P Extends GO Method Create(x:Float, y:Float) Super.x = x Super.y = y End End Class E Extends GO Method Create(x:Float, y:Float) Super.x = x Super.y = y End End |
| ||
when you define the project as Strict you need to define the returned parameter for all of your methods and functions. In case of the Create you need to define it as: Method Create:Void(x:float,y:float) |
| ||
I totally forgot about that, thank you.. Like stated before I'm at working, and just trying to work on stuff I'm there.. I was also wanting to know is how can I make a Array Function or Method, and assign information to it though the parameters.. I have seen it before and I couldn't find it on the forum.. Thanks, |