|
Re: Customized getters and setters [message #417304 is a reply to message #417299] |
Tue, 04 March 2008 22:06 |
Ed Merks Messages: 33140 Registered: July 2009 |
Senior Member |
|
|
Daniel,
Comments below.
Daniel wrote:
> Hi,
>
> I want to generate an EMF model from an UML diagram.
>
> Several classes are derived from an abstract super class called
> "Identifiable" which specifies an attribute Name : String.
>
> I have a class A which has a containment reference for B where B extends
> Identifiable.
>
> A<>-----B
> a bs
> 0..*
>
> Normally EMF only generates a "getBs()" Method which returns a list of all
> B's.
>
> Is it possible to extend it in some way, so that I can generate a method
> such as
> "getBsByName(String name)", i.e. in the best case, all instances of B would
> be stored in a map within A, where the key is the name attribute of B and
> the value the instance of B itself.
>
You could add such a method by hand though. Keeping a map up-to-date
with specific to name values would could potentially change is a bit
tricky. What you're doing is not so different from EPackage's
getEClassifier method.
> I now that it is possible to force the EMF generator to generate a Map by
> introducing an additional EClass called <KeyType>2<ValueType>, but I don't
> want to have this in my UML model.
>
> Moreover, convenience methods such as
> B A.addToBs();
> void A.removeFromBs(B elementToRemove);
>
What's wrong with a.getBs().remove(b) or add(b)? It seems a whole
whack of method to duplicate what you can do with the List API is not
all that convenient, but you could add them by hand (or as an EOperation
with a body annotation).
> would be nice to have...
>
> Thanks in advance for answers,
>
> Daniel
>
>
>
>
>
Ed Merks
Professional Support: https://www.macromodeling.com/
|
|
|
Powered by
FUDForum. Page generated in 0.05406 seconds