
...
This noncompliant code example shows two classes, BadClone
and Sub
. The class BadClone
calls an overridable method doSomething()
. The overridden method sets the value of the cookies; the overriding method sets the values of the domain names. The doSomething()
method of the subclass Sub
is erroneously executed at runtime, because of polymorphism. The subclass not only sees the clone in an inconsistent state, but also modifies the clone in a manner that creates inconsistent copies. This is because the deepCopy()
method occurs after the call to the doSomething()
method and the overriding doSomething()
implementation erroneously modifies the object .
...