Change Request #3877

Updated by Tiziano Munaro 11 months ago

Checks of the type
<pre><code class="java">
Object model = mvcb.getModel();
if(!(model instanceof ILayoutedModelElement)) {
throw new IllegalArgumentException(
"Expected model of type ILayoutedModelElement, but was " +
model.getClass().getSimpleName() + ".");
shall be moved to a common base class within the SystemFocus kernel. @MVCBundlePartBase@ would be the most common class to place such a check. This way the class itself does not have to be parameterized while still avoiding code duplication.
The same base class could be accomodate a generic method for returning the casted model element:
<pre><code class="java">
protected <T> T getModelElement(Class<T> elementType)
Of course calling this method with a wrong parameter leads to class-cast exceptions, but the expected type is already checked in the constructor. Also, a misuse is limited to derived classes, where an a contributor contributer should know the context.