Select grandparent from a grandchild ?

185 views
Skip to first unread message

Nicolas Vereenoghe

unread,
May 22, 2017, 6:21:07 AM5/22/17
to Haxe
Hello,

I would like to know if there's a technic to call a specific grandparent member from within a grandchild.

The "super" keyword allows to call the parent, but I don't find how to call the grandparent (super.super is not allowed), ie :

class GrandParent {
function buildContent() : Void {
trace( "grand parent"); 
}
}

class Parent extends GrandParent {
override function buildContent() : Void {
super.buildContent();
trace( "parent"); 
}

class Child extends Parent {
override function buildContent() : Void {
// WRONG : C++ 'ish synthax to call the grandparent's method instead of its parent 
GrandParent::buildContent();
}

In ActionScript or Javascript you could do the trick thanks to "prototype" and "call" keywords. Please, could you tell me how to deal with this in Haxe ? Thanks :)

Juraj Kirchheim

unread,
May 22, 2017, 6:47:32 AM5/22/17
to haxe...@googlegroups.com
You can keep the old implementation around:

class GrandParent {
function buildContent() : Void {
trace( "grand parent"); 
}
}

class Parent extends GrandParent {
           function GrandParent_buildContent() 
                       super.buildContent();
override function buildContent() : Void {
super.buildContent();
trace( "parent"); 
}

class Child extends Parent {
override function buildContent() : Void {
// WRONG : C++ 'ish synthax to call the grandparent's method instead of its parent 
GrandParent::buildContent();
}

Furthermore, you could use a build macro to auto-generate these "archive" methods for you.

That said: consider using composition over inheritance ;)

Best,
Juraj


--
To post to this group haxe...@googlegroups.com
http://groups.google.com/group/haxelang?hl=en
---
You received this message because you are subscribed to the Google Groups "Haxe" group.
For more options, visit https://groups.google.com/d/optout.

Nicolas Vereenoghe

unread,
May 22, 2017, 7:09:35 AM5/22/17
to Haxe
Thanks for the answer ^^

Without the possibility to specify a grandparent, that's indeed how I manage this : the overriden method call a specific method, so that later I could override that specific method. It's just a bit more heavy to write, compared to ActionScript / Javascript / C++ ^^

I was just wondering if there was something into Haxe language to manage this concept of grandparent selection ... without macro or changing design (I don't always own the libraries).
Reply all
Reply to author
Forward
0 new messages