haXe Forum > Abstract classes/methods in HaXe
-
Bas van Meurs Jan 23 at 16:34
Hello, this HaXe language seems pretty interesting. I'm studying it now to find out if this language has the power to build a Zend/CodeIgniter-like framework on, but I have two burning questions:
- How do you define abstract methods/classes? I can't find it anywhere in the documentation, but it's a basic feature of object orientation.
- How could you use, for instance, the PHP gdlib library? On the 'why use HaXe' page it is mentioned that you can 'Easily access to PHP's full list of functionality by writing wrapper classes', but how?Regards,
Bas -
ludo Jan 24 at 22:39
Hello,
I think you can create a private constructor for your abstract class...
You should have a look on the haxigniter framework. It's a framework inspired by codeigniter. -
ludo Jan 24 at 22:58
For your second question you can take a look on this tutorial.
-
ludo Jan 24 at 23:08
You can also take a look on php magic.
best regards,
loudoweb -
Bas van Meurs Jan 25 at 12:30
Hi Ludo, thanks.. it seems that the __call__ function and 'extern' mechanism provides enough flexibility to integrate GDLib functionality :-) I like the wrapper class idea.
I'm not sure what you mean with the private constructor comment, but I've seen another example stating that you can do this by making it necessary to provide an interface containing the definitions of the abstract methods in the constructor. Indeed, by making this constructor private we have a work-around for abstract classes, but it would be necessary to have 2 seperate classes; and imho it's less powerful than the 'real abstract classes'. It should be doable to incorporate this functionality in HaXe.
-
ludo Jan 25 at 14:15
example:
class Machine { private var pound:Int; private var fuel:String; private function new(pound,fuel) { //implementation of parameters } public function startEngine() { //... } } class Car extends Machine { public function new(pound,fuel) { super(pound, fuel); /*it works, it can call the constructor even if it's in private*/ //implementations } override public function startEngine() { } /* you must use overriding*/ public function carFunction(){} } class Main { static function main() { //var myMachine:Machine = new Machine(0, 'oil'); /*it doesn't work*/ var myCar:Car = new Car(0, 'oil'); } }
don't you think it's correct?
-
Bas van Meurs Feb 08 at 20:33
Thanks! I understand now what you mean by the private constructor, and I think it's a good solution and will use it. However, imho still it's a bit less powerful than 'real' abstract methods, because the check is done at run time rather than at compile time. Therefore, it would make code a bit more reliable if abstract classes were actually implemented.