= Solution
Override the operation and scale the result of exactly one superclass call:
``
class ScaledSumChannel(factor: Int) extends SumChannel {
override def apply(n: Int): Int = factor * super.apply(n)
}
``
The superclass updates its previous-input state once and returns its ordinary sum; only that returned value is scaled. \b[The inputs and superclass history are unchanged by the scaling.] Reimplementing the state update is unnecessary and could accidentally diverge from the superclass contract. As in the supplied channel, arithmetic uses the declared fixed-width <integer> type.
Back to article page