Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » Model: abstract or interface?
Model: abstract or interface? [message #1745823] Tue, 18 October 2016 00:04 Go to next message
Emil Jenotte is currently offline Emil JenotteFriend
Messages: 25
Registered: September 2016
Junior Member
Hello,

I have a modelling question. I have read the thread [1] and have had a look into the EMF Book, but I still can not get it clear, when I should model a class as abstract and when as an interface.

In my model, I would like to use abstract/interface classes for mother nodes that contain attributes (no methods/operations yet, but maybe they might have them in future). Other child are inheriting from these mother nodes.

In context of EMF I don't see multiply inheritage an issue with abstract classes (as if working with plain Java). Or am I wrong?

So to sum it up my question is: When and why should I decide to model a class, of which I do not want that any instance to be created, as an interface and when as an abstract class?

Hope you can help.
Cheers
Emil

[1] https://www.eclipse.org/forums/index.php/t/128666/
Re: Model: abstract or interface? [message #1745836 is a reply to message #1745823] Tue, 18 October 2016 08:11 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33142
Registered: July 2009
Senior Member
Modeling an EClass X as an interface (as opposed to merely abstract) is useful only when it's actually an optimization of how much Java code is generated. I.e., for each EClass Y that has X as an eSuperType, does the generated YImpl extend XImpl? If there is more than one such YImpl that extends XImpl, then the XImpl is being reused multiple times and as such is an optimization. So ask yourself, in which case will YImpl not extend XImpl? That will only happen if Y has more than one eSuperType and X is not the first eSuperType.

Ed Merks
Professional Support: https://www.macromodeling.com/
Re: Model: abstract or interface? [message #1745845 is a reply to message #1745836] Tue, 18 October 2016 10:48 Go to previous messageGo to next message
Emil Jenotte is currently offline Emil JenotteFriend
Messages: 25
Registered: September 2016
Junior Member
Hello Ed,

thanks for the quick answer. That helps me a lot! Thank you so much!
But this rasises a few questions for me:
1. Why then do I not model all my classes as interfaces straight away? What disadvantage has it to define a class as an interface even though an abstract class would be enough?
2. Only the first eSuperType gets an extend? What about the other eSuperTypes of my class? And what does it mean, if my class extends MinimalEObjectImpl.Container ?

Cheers
Emil
Re: Model: abstract or interface? [message #1745898 is a reply to message #1745845] Wed, 19 October 2016 05:56 Go to previous message
Ed Merks is currently offline Ed MerksFriend
Messages: 33142
Registered: July 2009
Senior Member
With with regard to 1., not all your classes are abstract so certainly not all your classes should be interfaces, multiple inheritance is not such a common pattern, and even when using multiple inheritance, you'll still generally want to reuse base class implementations as much as possible.

With regard to 2., you have a tool, you can write examples and see what they generate. I'm not here simple to describe hypothetical things that you might not be using in practice. You can answer such questions yourself. I suggest you create the classic diamond inheritance with A, B -> A, C -> A, D -> B, C and see how that's actually implemented by generated code.


Ed Merks
Professional Support: https://www.macromodeling.com/
Previous Topic:Adapters
Next Topic:[XCore] Cross-Reference vs Container Reference
Goto Forum:
  


Current Time: Fri Apr 26 19:23:13 GMT 2024

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

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

Back to the top