Skip to main content

Constraint specifications in bank account model

Short answer

Constraints add precision by stating rules. The model contains: {secure} restricts access to the portfolio-account link; {or} makes BankAccount either Corporation or Person exclusively; gender : {female, male} limits attribute values; and the marriage invariant ensures wife's gender is female and husband's male.

What is the role of constraint specifications in a model diagram? The model below depicts about possible types of accounts within the portfolio sub-head in any banking business domain. Identify the constraints highlighted and explain in brief, what they mean. [Figure: class Portfolio linked to class BankAccount with constraint {secure}. BankAccount is generalized into Corporation and Person, with an {or} constraint across the generalization. Person has the attribute gender : {female, male}. Person has a self-association, role husband 0..1 and role wife 0..1, with the constraint (self.wife.gender = female and self.husband.gender = male).]

Role of constraints

A constraint in UML is a condition or restriction placed on a model element. It gives more precise meaning than the graphical notation can show. It is written in braces { } or as a note, often in OCL (Object Constraint Language). Constraints

  • state rules and invariants that the system must keep,
  • remove ambiguity in the model,
  • help in checking, testing and generating code, and
  • can be attached to classes, associations, generalizations and attributes.

Constraints in the bank account model

 +-----------+  {secure}  +-------------+
 | Portfolio |------------| BankAccount |
 +-----------+            +-------------+
                                ^
                                | {or}
                      +---------+---------+
                +-------------+     +---------------+
                | Corporation |     |    Person     |
                +-------------+     | gender :      |
                                    | {female,male} |
                                    +---------------+
        Person (husband 0..1) -------- (wife 0..1) Person
        {self.wife.gender = female and self.husband.gender = male}
  1. {secure} on the association between Portfolio and BankAccount: the accounts of a portfolio must be protected, so the link between a portfolio and its accounts may be used only through authorised access. It is a user-defined constraint stating that this relationship must be secure.
  2. {or} on the generalization: a BankAccount is either a Corporation account or a Person account, never both at once (disjoint specialization).
  3. gender : {female, male}: an attribute constraint (enumeration). The attribute can take only one of the two listed values.
  4. self.wife.gender = female and self.husband.gender = male: an OCL invariant on the self-association of Person (marriage). For a Person object self, the person in its wife role must be female and the person in its husband role must be male. The multiplicities husband 0..1 and wife 0..1 mean that a person has at most one husband and at most one wife.

These constraints make the model precise. They prevent invalid data such as an account owned by both a person and a corporation, or a marriage in which the "wife" is male.

✓ Answer checked by Claude Sonnet 5.5

All Object Oriented Analysis and Design chapter 2 questions →