jdbaker@computer.org

[email protected]

J.D. Baker

Armstrong Process Group (Consultant)
 
J.D. Baker, Principal Systems Engineer with Armstrong Process Group, Inc., is a recognized expert in software and system architecture, systems engineering, software development, iterative/agile development, object-oriented analysis and design, the Unified Modeling Language (UML), the UML Profile for Systems Engineering (SysML), use case driven requirements, and process improvement. His activities have included research and development of services for automatic test, leading the development of a model-based methodology for the design and construction of complex systems, and providing modeling support for teams creating OMG standards.

It is no coincidence that the package element in UML is represented by a folder icon, similar to directories in a file system Graphical User Interface (GUI).  Packages are used to organize the elements of a model just as folders are used to organize files.  The contents of a package are any kind of element that is part of a model, including other packages.  Beyond that description there's not much more information on how to use packages in the UML specification.  Since they are a general grouping thing, it is up to usage scenarios to suggest what the best practices are for using packages.  There are some practices that apply in most situations, and more that depend upon the modeling methodology or the purpose of the model.

First and foremost, use packages to organize your model, regardless of the model purpose.  Even the most trivial model quickly becomes unmanageable without some kind of organization.  There is no single correct way to organize a model.  A modeler may choose to organize around process or product or some combination of the two.   Second, use the package diagram to provide visualizations of that organization.   The model browser view below illustrates how even a simple model can begin to be confusing with no organization of the model elements.

 

 In addition to being able to gather like items together to allow modelers to focus their attention on relevant elements and make those elements easier to find in the browser, packages provide a namespace for the elements they contain.  Namespaces allow modelers to create unambiguous named references to each of the elements in a model.  This is useful in situations such as when a modeler is evolving a system and creating an as-is and a to-be system model.   It is natural to have elements named the same in each model.  In order to disambiguate elements with the same name, they can be placed in different packages so that the fully-qualified names are different.

Packages can be placed on a UML package diagram.  The modeler might choose to do this to present a high-level view of a model or to show relationships among the packages of elements.  Three different package diagrams representing the model organization shown above are presented here.  Each of these diagrams uses the optional diagram frame, showing the diagram type (pkg) and diagram name (Use Case View).  Note that although  the diagram and the package have the same name (Use Case View) this is not required.  In the first diagram, the two high-level packages are shown.  As with many other modeling situations, only the details we need are presented, and the details of the package contents are elided.

 

In the second diagram, the packages contained in the Actors package are shown.  The labels on the Human and Non-Human package describe the namespace of the containing package.  The containment relationship also serves to describe the namespace.  In this example, the fully qualified name of the Actor Operator is Use Case View::Actors::Human::Operator.

 

In the third diagram, the contents of the packages are shown embedded in the package elements.  This representation is the third presentation option found in the UML specification.

Your package diagrams will in all likelihood be some combination of each of these styles, as will your choice of organizing principles.  Choose the one that is appropriate for its intended use. 

 

Monday, 16 July 2012 18:57

Adding Connectors to Diagrams

To execute this script import it into a model, open a diagram, right-click a class element and select Scripts | AddConnectorDemo. In the example model, add_con_demo, the script is located in the APG Diagram Scripts group. To install the script from the XML file:

Installation

Open the model

Import the script to set the «RequirementsRelated» association

- Project | Model Import/Export | Import Reference Data

- Select the add_con_demo.xml script file

- Select Automation Scripts in the import dialog box

- Select Import

- If it's not already opened, open the Scripting window

-- View | Scripting

- press the Refresh the Script Tree button in the Scripting window

- Verify that the APG Diagram Scripts group contains the AddConnectorDemo script

option explicit

 

!INC Local Scripts.EAConstants-VBScript

 

    '

    ' Script Name: AddConnectorDemo

    ' Author:J.D. Baker

    ' Purpose:Assign a relationship for elements in a class diagram.  This technique

    ' should work for any diagram type

    ' Date:10 July 2012

    '

    '

    ' Diagram Script main function

    '

sub OnDiagramScript()

    ' dim objects for setting connectors

    Dim i

    Dim target As EA.Element

    Dim source As EA.Element

    Dim association As EA.Connector

 

    ' Get a reference to the current diagram

    Dim currentDiagram As EA.Diagram

    currentDiagram = Repository.GetCurrentDiagram()

 

    If Not currentDiagram Is Nothing Then

      ' Get a reference to any selected connector or objects

      Dim selectedConnector As EA.Connector

      Dim selectedObjects As EA.Collection

      selectedConnector = currentDiagram.SelectedConnector

      selectedObjects = currentDiagram.SelectedObjects

 

      If Not selectedConnector Is Nothing Then

        ' A connector is selected

        Session.Prompt("This script requires that only an Class element be selected", promptOK)

      ElseIf selectedObjects.Count > 0 Then

 

        Dim currentElement As EA.DiagramObject

        currentElement = selectedObjects.GetAt(0)

 

        ' One or more diagram objects are selected

        'currentElement is a diagramObject.  We need to get the corresponding element in the project browser

        source = Repository.GetElementByID(currentElement.ElementID)

        ' test to see that the object selected is a Class

        If (source.Type = "Class") Then

 

          'now we need to identify all of the non-selected objects

          Dim allObjects As EA.Collection

          allObjects = currentDiagram.DiagramObjects

          Dim thisObject As EA.DiagramObject

          'now loop through the collection of objects setting a realization with

          'a RequirementRelated stereotype to all objects

 

          For i = 0 To allObjects.Count - 1

            'get the next DiagramObject

            thisObject = allObjects.GetAt(i)

            'make sure we don't create a self reference to the selected object

            If thisObject.ElementID <> currentElement.ElementID Then

              target = Repository.GetElementByID(thisObject.ElementID)

              'before creating a new relationship, check to see if one already exists

              'If there is no existing relationship and the target is the correct type,

              'add one to the collection of connectors for this source

              If (target.Connectors.Count = 0 And target.type = "Interface") Then

                association = source.Connectors.AddNew("", "Realization")

                'now connect it to the target

                association.SupplierID = target.ElementID

                association.Stereotype = "RequirementRelated"

 

                'the space surrounding the -> operator is essential if you are

                'creating a directed association.  Note the discontinuity between

                'the use of the identifiers target and destination

                'association.Direction = "Source -> Destination"

 

                association.Update()

              End If

            End If

          Next

 

          Repository.ReloadDiagram(currentDiagram.DiagramID)

        Else

          Session.Prompt("You must run the script with a Class element selected", promptOK)

        End If

      Else

        ' Nothing is selected

        Session.Prompt("Nothing selected. This script requires a Class to be selected", promptOK)

      End If

    Else

      Session.Prompt("This script requires a diagram to be visible", promptOK)

    End If

   End Sub

 OnDiagramScript