Discount class abstract base

Sconto applicabile a una riga o all'intero documento.

Gerarchia chiusa e polimorfa: ogni tipo di sconto sa calcolarsi da solo. La versione precedente usava uno switch su un enum, e questo violava l'Open/Closed Principle — aggiungere uno sconto quantità o un "3x2" obbligava a modificare il metodo di calcolo. Così invece si aggiunge una sottoclasse e non si tocca niente di esistente.

sealed mantiene comunque l'esaustività: il compilatore segnala ogni switch sui sottotipi rimasto scoperto.

Implementers

Constructors

Discount({String description = ''})
Costruttore delle sottoclassi.
const

Properties

description String
Motivo dello sconto, da stampare sullo scontrino. Non entra nel calcolo.
final
hashCode int
The hash code for this object.
no setterinherited
runtimeType Type
A representation of the runtime type of the object.
no setterinherited

Methods

appliedTo(Money base) Money
Importo dello sconto calcolato su una base imponibile.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
toString() String
A string representation of this object.
inherited

Operators

operator ==(Object other) bool
The equality operator.
inherited

Static Methods

amount(Money value, {String description = ''}) Discount
Sconto a importo fisso.
percent(num value, {String description = ''}) Discount
Sconto percentuale (es. Discount.percent(10) per il 10%).