Skip to main content



      Home
Home » Modeling » M2T (model-to-text transformation) » [Xpand] super() equivalent for DEFINE methods?
[Xpand] super() equivalent for DEFINE methods? [message #659411] Sun, 13 March 2011 13:51 Go to next message
Eclipse UserFriend
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 13:55] by Moderator

Re: [Xpand] super() equivalent for DEFINE methods? [message #659415 is a reply to message #659411] Sun, 13 March 2011 14:23 Go to previous messageGo to next message
Eclipse UserFriend
Sorry, here's a more sensible code demonstration (I edited the original message posting to match this.)

«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»

Re: [Xpand] super() equivalent for DEFINE methods? [message #659421 is a reply to message #659415] Sun, 13 March 2011 14:56 Go to previous messageGo to next message
Eclipse UserFriend
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
Re: [Xpand] super() equivalent for DEFINE methods? [message #659607 is a reply to message #659421] Mon, 14 March 2011 15:26 Go to previous messageGo to next message
Eclipse UserFriend
Thanks very much Christian. This does work, however it seems to violate the open/closed principle.

When I want to extend behavior, I have to modify the method of the parent class at the point I want to inject the new behavior. Or am I misunderstanding something?

If this is true, does anyone know if this limitation is going to be addressed in Xtend2?

Jeff
Re: [Xpand] super() equivalent for DEFINE methods? [message #659609 is a reply to message #659607] Mon, 14 March 2011 15:37 Go to previous message
Eclipse UserFriend
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

[Updated on: Mon, 14 March 2011 17:49] by Moderator

Previous Topic:[Xtend] access static field/method
Next Topic:[MWE2] Workflow execution fails randomly
Goto Forum:
  


Current Time: Wed Jul 02 17:24:37 EDT 2025

Powered by FUDForum. Page generated in 0.04873 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top