UML Associations and Dependencies (Java)

Context: FIT2099_MOC · name the arrows between classes in a UML classDiagram · which client–supplier link is which · full notation legend in UML Class Diagrams (Java) Parent Framework: Client-Supplier Relationship (Java)

Quick Revision

  • 🎯 Objective: distinguish association (has-a, a stored field) from dependency (uses-a, a transient method parameter/return) ➔ draw the right arrow.
  • 📦 Core Components: association (solid -->, an attribute) | dependency (dashed ..> «use», a parameter) | multiplicity (1, *, ranges).
  • ⚡ Key Constraint: FIT2099 will NOT ask you to use Aggregation or Composition — focus your modelling on Association, Dependency, and Inheritance. Know aggregation/composition only to read diagrams.

📝 How It Works

1. Association — “has-a” (persistent)

  • Definition ➔ one class holds another as a field and uses it over its lifetime.
  • UML ➔ solid line / arrow A --> B; label with a role and multiplicity.
  • Code smell for it ➔ the other class appears as an attribute in the class body.

2. Dependency — “uses-a” (transient)

  • Definition ➔ one class uses another only briefly — as a method parameter, return type, or local variable — not stored.
  • UML ➔ dashed arrow A ..> B stereotyped «use».
  • Rule of thumb ➔ if it’s a stored field ➔ association; if it just passes through a method ➔ dependency.

3. Multiplicity

  • 1 ➔ exactly one · 0..1 ➔ optional · * / 0..* ➔ many (often an array/ArrayList) · 1..* ➔ one or more · 2 ➔ exactly two.

4. Aggregation vs Composition (read-only for FIT2099)

  • Aggregation ➔ hollow diamond ◇ — a “whole-part” where the part can outlive the whole; often a modelling placebo (adds little over plain association).
  • Composition ➔ filled diamond ◆ — the whole is responsible for creating the part and controls its lifetime (part dies with the whole).

⚙️ Core Implementation

🔹 SmartHomeDriver — association + dependency

When It Flips: more associations and dependencies = more coupling. Judge a design on Domain-B metrics — prefer fewer, thinner links to small public interfaces; a dependency (transient) is looser coupling than an association (stored) for the same collaboration.

🧠 Active Recall