SE450: Basics: Composition (Exclusive Reference) [39/63] Previous pageContentsNext page

file:Person.java [source] [doc-public] [doc-private]
01
02
03
04
05
06
07
08
09
package basics.composition;
import java.util.Random;
final class Person {
  static private Random random = new Random();
  final  private String name;
  public Person() { name = Integer.toString(random.nextInt()); }
  //public Person(String name) { name = name.clone(); }
  public String toString() { return "Person(" + name + ")"; };
}

Exclusive reference to objects of another class:

   +--------+    name  +--------+
   | Person |<@>------>| String |
   +--------+          +--------+

In UML, this is called composition.

Consequences of composition:

(Yuck! We've mixed static and non-static members!)

Previous pageContentsNext page