---
title: "Constraint specifications in bank account model"
subject: "Object Oriented Analysis and Design"
chapter: 2
key: "semester_6/object_oriented_analysis_and_design:constraint-specification-bank-account-model"
source: https://www.bctengineer.com/q/semester_6/object_oriented_analysis_and_design/constraint-specification-bank-account-model
site: BCT Engineering
---

# Constraint specifications in bank account model

Object Oriented Analysis and Design · Chapter 2: Object Oriented Analysis

- Asked in: 2071 Magh, 7 marks
- Video: [Lecture Video 2.3.12 - Building OCL Expressions](https://www.youtube.com/watch?v=t72Yo5kn0Oo) — Evita Coelho
- Answer checked by Claude Sonnet 5.5 on 2026-10-14
- Page: https://www.bctengineer.com/q/semester_6/object_oriented_analysis_and_design/constraint-specification-bank-account-model
- Whole chapter: https://www.bctengineer.com/md/semester_6/object_oriented_analysis_and_design/chapter-2

## Question

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).]

## 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.

## Answer

#### 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

```text
 +-----------+  {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.

## Check yourself

The answer's key points as multiple-choice questions, with the correct option and why.

1. What is the role of a constraint in a UML model?
   A. To draw the classes with colours
   B. To replace attributes
   C. To give more precise semantics by stating rules the model must keep
   D. To delete associations
   Answer: C. A constraint is a condition on a model element, written in braces or OCL, that removes ambiguity and states rules. (Key point: Role of constraints)

2. What does {or} on the BankAccount generalization mean?
   A. An account is both a Corporation and a Person account
   B. An account is either a Corporation or a Person account, never both
   C. An account may have no owner
   D. A Person has two accounts
   Answer: B. {or} is a disjoint specialization: exactly one of the subclasses applies to an account. (Key point: {or} constraint)

3. What does self.wife.gender = female and self.husband.gender = male state?
   A. Any person can be a wife regardless of gender
   B. A person has exactly one husband and one wife
   C. Gender is optional for a Person
   D. A person's wife must be female and husband must be male
   Answer: D. It is an OCL invariant on the self-association: the wife role must be female and the husband role male. (Key point: OCL constraint on marriage)

4. What does gender : {female, male} specify?
   A. The attribute can take only one of the two listed values
   B. A Person has two genders at once
   C. Gender is a separate class
   D. Gender is derived from the account
   Answer: A. It is an enumeration constraint limiting the attribute to the listed values. (Key point: Attribute enumeration constraint)

## Related in Object Oriented Analysis and Design

- [Identify conceptual classes; create domain model](https://www.bctengineer.com/question.md?key=semester_6%2Fobject_oriented_analysis_and_design%3Aconceptual-classes-domain-model-steps) — Object Oriented Analysis and Design, chapter 2
- [XYZ Marina class diagram](https://www.bctengineer.com/question.md?key=semester_6%2Fobject_oriented_analysis_and_design%3Amarina-class-diagram) — Object Oriented Analysis and Design, chapter 2
- [Event management system summary and class diagram](https://www.bctengineer.com/question.md?key=semester_6%2Fobject_oriented_analysis_and_design%3Aoems-executive-summary-class-diagram) — Object Oriented Analysis and Design, chapter 2
- [Video rental shop class diagram](https://www.bctengineer.com/question.md?key=semester_6%2Fobject_oriented_analysis_and_design%3Avideo-rental-class-diagram) — Object Oriented Analysis and Design, chapter 2
- [Point of sale class diagram](https://www.bctengineer.com/question.md?key=semester_6%2Fobject_oriented_analysis_and_design%3Apos-class-diagram-multiplicity) — Object Oriented Analysis and Design, chapter 2
- [Deployment diagram as class diagram of nodes](https://www.bctengineer.com/question.md?key=semester_6%2Fobject_oriented_analysis_and_design%3Adeployment-diagram-special-class-diagram) — Object Oriented Analysis and Design, chapter 3

## Related in other subjects

- [Time-domain specifications of 25/(s²+8s+25)](https://www.bctengineer.com/question.md?key=semester_3%2Fcontrol_systems%3Atr-tp-ts-mp-25-s2) — Control Systems, chapter 3
- [SQL: number of accounts per branch](https://www.bctengineer.com/question.md?key=semester_6%2Fdatabase_management_system%3Asql-count-accounts-branch) — Database Management System, chapter 3
- [Spillway model height, head and flow](https://www.bctengineer.com/question.md?key=semester_3%2Ffluid_mechanics%3Aspillway-model-height-head-flow) — Fluid Mechanics, chapter 10
- [Channel fully in banking, 0.5-1.5 km](https://www.bctengineer.com/question.md?key=semester_7%2Festimating_and_costing%3Acanal-fully-banking-i) — Estimating and Costing, chapter 6
