An immutable object has no changeable observable state after its object constructor finishes. Two clients may hold references to the same immutable object, but neither can change what the other observes. Thus sharing an immutable object avoids the interference normally associated with reference aliasing: for example, sharing a Java String is safe because a text-changing operation returns another software object rather than modifying that String data type value.
A final reference alone does not establish an immutable object: it prevents reassignment of that reference, but its referent could still be mutable. An immutable object must also protect any reachable mutable state, for instance through defensive copying. With that qualification, the essential answer is
The Prototype pattern is a creational pattern that creates new software objects by copying an existing configured object through a common cloning object interface. A client keeps or selects a prototype and requests a copy, without naming the concrete software class or repeating its construction recipe.
It is useful when the concrete type is selected at runtime, when many objects share a configuration, or when reconstructing an initialized object is expensive. For example, a drawing application can duplicate a configured graphical object through the same interface for many shape classes. The contract must specify what is copied: nested mutable state may require a deep copy, whereas a shallow copy would retain reference aliasing. A copy should preserve the intended configuration while allowing independent changes where promised.
Allocate a fresh array and copy every digit:
function CopyNum(n: number): number
    new(result, len(n))
    for i := 0 to len(n)-1 do
        result[i] := n[i]
    return result
Every coefficient in the digit-array integer representation is unchanged, so the value is unchanged. The new array shares no storage with n; assigning one pointer to the other would instead create reference aliasing. Since the entries are integers, copying the entries also gives the required deep copy of this representation.
The prototype pattern is a creational pattern: a client asks a configured object to clone itself through a common object interface, and concrete prototypes implement the cloning operation. The client can thereby create objects without naming their concrete classes at every creation site.
Use it when the required configuration or concrete type is chosen at runtime, or when reconstructing expensive initial state is less convenient than copying a prepared example. A deep copy may be needed for independently mutable nested data; merely duplicating outer fields can leave reference aliasing. The cloning contract determines what is copied and what may safely be shared.
The constructor stores a reference, not a copy:
val d = new Dimension(3, 4)
val f = new Frame(d)
d.width = 10
Now f.area is still , but the product of its stored dimension fields is . Even without retaining d, a client can break the same invariant through f.dimension.height = 9, because the accessor exposes the same mutable object. This is representation exposure through reference aliasing. A val prevents reassigning the reference; it does not freeze the referenced object.
Yes: the mutable specification omits important state and frame clauses. Queries do not explicitly preserve the receiver, so an implementation could clear its state during present, return an empty sequence, and satisfy the displayed coverage condition in the resulting state. Arithmetic does not explicitly preserve a distinct operand, so it could corrupt that operand as well as update the receiver. No initial value or independence requirement for copy is stated.
The missing old-state annotation on the other operand is particularly serious under reference aliasing. If other is the receiver, the printed addition equation becomes , which is impossible for a nonzero old count. Self-subtraction becomes rather than the intended zero; self-maximum admits arbitrarily increased counts. Specify instead, for every key,
with both operands evaluated in their pre-states. Queries preserve all states; updates change only the receiver's abstract value and preserve a distinct operand; copy produces an independent snapshot of the argument's pre-state. Specify an empty initial state and checked representable arithmetic, or use unbounded counts.
The fact that present may contain duplicates or zero-count keys is not itself a violation: the printed condition expressly requires only a support-covering sequence. An implementation may strengthen this to an exact, duplicate-free support. Efficiency also needs a cost model or explicit bounds if it is to be a formal guarantee rather than an informal aspiration.
Prototype pattern 2026-10-31
Expose a cloning operation through a common object interface and create new objects by asking a configured prototype for a copy. Concrete prototypes implement the copy operation; the client need not name their concrete software classes. This is useful when creation depends on runtime configuration or expensive reusable initial state. The contract must specify whether nested mutable data requires a deep copy; copying only outer fields can preserve unintended reference aliasing.
Reference parameter Created 2026-10-31 Updated 2026-11-05
A reference parameter designates the caller's actual storage. Assigning through it can change what the caller subsequently observes; passing a complete independent copy would instead change only the local copy. A value parameter containing an object reference is another case: copying that reference does not copy the referenced software object.
In Oberon, a variable parameter is marked VAR and stands for the supplied actual variable. For example, a procedure accepting VAR x: INTEGER can increment the caller's integer through x.[ref]
A read-only algorithm can use a reference parameter to avoid copying a large array, while its formal specification still prohibits writes. Reference aliasing remains relevant: two parameters can designate overlapping storage. A proof of algorithm correctness must account for the actual aliasing rules rather than assume that different parameter names denote independent values.
Software object 2026-10-24
An object combines an identity, state and operations exposed through an object interface. Distinct software objects can hold equal data while remaining different by object identity. Reference aliasing occurs when multiple references designate the same object, so a state update through one reference can affect observations through another.