Return Wrapped Object Pattern

Any time we have an EA object return another object we need to catch the operation and return an equivalent wrapper for the object returned.  To handle these cases we use the Return Wrapped Object Pattern, which is illustrated by the following example code.

get element() {
    return this.elementFactory.newElementWrapper(
        this.wrappedObject.Element
    );
}

That is a getter is defined for the wrapper class which calls a factory method to return the wrapped equivalent.

A variation on the above is when an EA object refers to the ID or the GUID of a related object.  For these cases a variation on the previous pattern can be used to achieve the same result.

get parent() {
    return this.repository.getElement(
        this.wrappedObject.ParentID
    );
}

That is, a getter is defined for the wrapper class which calls the repository object (actually the RepositoryWrapper object) to retrieve the relevant ElementWrapper corresponding to the ID in question.  

Note that getElement() implements the Flexible Method Pattern to determine the specific Respository method depending on the type of id passed - in this case the GetElementByID() method.

Comments

Popular posts from this blog

Creating Items in Sparx EA via Java

Module Management - Part 1 - getModule() Pattern

Traversing a EA Model via Java