Chapter 11

Software implementation from UML

Mapping the model to code

  1. Operations on the object model
    • Optimisations to address performance requirements
  2. Implementation of class model components
    • Implementation of classes
    • Implementation of associations
    • Implementation of operation contracts
  3. Realising entity objects based on seleted storage stategy
    • Mapping the class model to a storage schema

Model transformation

To simplify or optimse the original model by adding or removing classes, methods and/or attributes.

For example, if an email address attibute is common among 3 subclasses of User, it could be pulled up to the super class as a protected attribute.

The disadvantage of this is that onstructors may have to be reworked to call super class constructors.

A class diagram will generally not contain low-level detail. Application frameworks make low level functionality available. For instance, a diagram editor applications will require code to manage the interaction of the application with the environment, detect user/input or provide graphics functions.

Application frameworks can be implemented for different target environments. For example, an applet framework that enables a diagram editor to be run in a browser and draw on a canvas.

Optimisation of the model

Repeated association traversals may have inefficient access paths. For example, one object calling another which in turn calls another. It may be better in this case to call the last object directly.

"Many" associations may create issues when it comes to searching. To reduce this, use qualified associations.

Remove classes without any behaviour. It is good practice to have classes with behaviours and attributes.

Add data structures to cache expensive computation results. For example, in a sports example, statistics may only change after a match is played, and an object ma be used to store the latest statistics.

User input/output

Sequence diagrams are good for representing input and output. The DiagramEditor inherits a moveMouse method via the Canvas. If, however, the DiagramEditor class overrides this method, it can first call the appropriate tool object, whether for driawing or selecting, and then repaint the updated Canvas.

Screenshot-2017-11-13-chapter11-software-implementation-ppt.png

Associations

In addition to this, some associations imply that one object is made up of another, even if an aggregation symbol is not used.

Mandatory (immutable) associations

public class Account {
  private Guarantor theGuarantor;
  
  public Account(Guarantor g) {
    if (g == null)
      // throw some Exception
    // Rest of constructor
  }
}

Optional associations

Screenshot-2017-11-13-chapter11-software-implementation-ppt(1).png

Associations with 'many' multiplicity

A data structure is needed to hold multiple references. Vectors, Arrays, Linked Lists, Hash Maps, Hash Tables etc, can be used.

1:1

When a CashCard is created, and it needs assigned to the account it belongs to, it can belong to one account only. In this case, allow Account to make the link.

public class Account{
  
  public void addCard() {
    theCard = new CashCard(this);
  }
  
}

1:*

Similar to 1:1, let the 1 side maintain responsibility for creating the link between the object(s).

Qualifiers / Qualified associations

With the help of a HashTable, information about Accont can be retrieves using an account number.

Screenshot-2017-11-13-chapter11-software-implementation-ppt(2).png

public class Bank{
  private HashTable<Integer, Account> accounts = new Hashtable<Integer, Account>();
  
  public void addAccount(Account a) {
    accounts.put(a.getNumber(), a);
  }
  
  public Account lookup(int accountNumber) {
    return (Account) accounts.get(accountNumber);
  }
}

 

No Comments

Back to top