[Xpand] super() equivalent for DEFINE methods? [message #659411] |
Sun, 13 March 2011 17:51  |
Glenview Jeff Messages: 79 Registered: September 2010 |
Member |
|
|
If CHILD inherits from PARENT, and I want to factor out common behavior, there appears to be no language support for calling the DEFINE of the superclass. Maybe this is because multiple inheritance is allowed?
Is there any way to accomplish this in Xpand? Acceleo suports this.
Thanks!
Jeff
«DEFINE someOtherDefine FOR Z»
«EXPAND implClass FOREACH listOfParentsAndChildren»
«ENDDEFINE»
«DEFINE implClass FOR PARENT»
common behavior goes here
«ENDDEFINE»
«DEFINE implClass FOR CHILD»
«SUPER()» (This feature doesn't appear to exist)
specialized behavior
«ENDDEFINE»
[Updated on: Sun, 13 March 2011 17:55] Report message to a moderator
|
|
|
|
Re: [Xpand] super() equivalent for DEFINE methods? [message #659421 is a reply to message #659415] |
Sun, 13 March 2011 18:56   |
|
Hi, won't one solve this like
«DEFINE someOtherDefine FOR Z»
«EXPAND implClass FOREACH listOfParentsAndChildren»
«ENDDEFINE»
«DEFINE implClass FOR PARENT»
common behavior goes here
«EXPAND implClassSpecial FOR thisn»
«ENDDEFINE»
«DEFINE implClassSpecial FOR CHILD»
specialized behavior
«ENDDEFINE»
«DEFINE implClassSpecial FOR PATENT»
«ENDDEFINE»
~Christian
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
|
|
|
|
Re: [Xpand] super() equivalent for DEFINE methods? [message #659609 is a reply to message #659607] |
Mon, 14 March 2011 19:37  |
|
Hi,
even if there would be something like a super call you have still the same problem:
the template for the parent class has to produce something that can be embedded in the stuff the child class - so you have the same problem as if you prepare "extension" points in the parent class.
maybe you can have a look at xpands aop feature and provide the child classes behaviours as aspects - but this might a bit ugly since the polymorphism stuff might not work as you expect / need it.
i guess you will have the same problem in xtend2 caused by muliple inheritance but i do not exactly know this since i did not play arround with xtend2 in that detail.
Update: I actually played a bit more arround with Xtend2 and it seems that you can solve the problem by Casting and en/disabling polymorphic dispatch.
package test
import java.util.List
class Test {
doSomeStuff(Model m) '''
model
«FOR e : m.getElements()»
«doSomeStuff4E(e)»
«ENDFOR»
endmodel
'''
dispatch doSomeStuff4E(Element e) '''
element commons stuff
'''
dispatch doSomeStuff4E(AElement e) '''
«_doSomeStuff4E(e as Element)»
aelement «e.name»
'''
dispatch doSomeStuff4E(BElement e) '''
belement «e.name»
'''
}
~Christian
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
[Updated on: Mon, 14 March 2011 21:49] Report message to a moderator
|
|
|
Powered by
FUDForum. Page generated in 0.02057 seconds