Login | Register
My pages Projects Community openCollabNet

argouml
Wiki: Repository Comparison With Model Interface

Revision 3 as of 2010-07-28 10:07:52 -0800

Edit this page | Links to this page | Page information | Attachments | Refresh page

 

Create an operation inside an interface

With Model Interface

   1 Object operationType = Model.getMetaTypes().getOperation();
   2 Object myOperation = Model.getUmlFactory.buildNode(elementType, myInterface);

The big drawback is that when a new model implementation is introduced that will introduce new model element types and the ?MetaTypes interface will continually need to adapt to provide a new getSomething() operation.

With Repository API

   1 MetaType operationType = repository.getMetaType("Operation");
   2 Element myOperation = operationType.createElement(myInterface);

A ?MetaType is requested from the Repository by a string identifier. That ?MetaType has the functionality to create instances.

One criticism of this technique is compile time safety. To help with this it would be possible to create a utility class with all the model element types already defined. This would be external to the repository API though. The example below uses a utility class called Type that has all the element types predefined as constants.

   1 Element myOperation = Type.OPERATION.createElement(myInterface);

This doesn't save much on notation but it does guarantee the Repository API remains stable no matter what else is added to the UML specification at any future time.

Add an existing element to another

With Model Interface

Separate methods have been provided for each model element type. Once again this API will have to adapt when new model element are introduced.

   1 Model.getCoreHelper().addOwnedElement(myNamespace, myInterface);
   2 Model.getCoreHelper().addFeature(myOperation, myInterface);
   3 Model.getCoreHelper().addParameter(myParameter, myOperation);

With Repository API

   1 myNamespace.add(myInterface);
   2 myInterface.add(myOperation);
   3 myOperation.add(myParameter);

Recognising Element Type

With Model Interface

Separate methods have been provided for each model element type. Once again this API will have to adapt when new model element are introduced.

   1 Model.getFacade().isANamespace(myElement);
   2 Model.getFacade().isAFeature(myElement);
   3 Model.getFacade().isAParameter(myElement);

With Repository API there is only one method to ever be aware of

   1 myElement.instanceOf(Type.NAMESPACE);
   2 myElement.instanceOf(Type.FEATURE));
   3 myElement.instanceOf(Type.PARAMETER);