at:tutorial:objects
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revision | Next revisionBoth sides next revision | ||
at:tutorial:objects [2007/07/27 16:31] – * tvcutsem | at:tutorial:objects [2007/08/04 11:02] – added tvcutsem | ||
---|---|---|---|
Line 235: | Line 235: | ||
< | < | ||
</ | </ | ||
+ | |||
+ | This pattern of creating objects by means of " | ||
+ | |||
+ | < | ||
+ | def b := makeBankAccount(100); | ||
+ | def b2 := b.new(); // shares its balance field with b! | ||
+ | b.deposit(10); | ||
+ | </ | ||
+ | |||
+ | In order to prevent this kind of errors, it is considered best practice to override '' | ||
+ | |||
+ | < | ||
+ | def makeBankAccount(balance) { | ||
+ | object: { | ||
+ | def new(@args) { makeBankAccount(@args) }; | ||
+ | def deposit(amnt) { /* as before */ }; | ||
+ | } | ||
+ | } | ||
+ | </ | ||
+ | |||
+ | By overriding '' | ||
===== Uniform Access ===== | ===== Uniform Access ===== |
at/tutorial/objects.txt · Last modified: 2013/05/17 20:23 by tvcutsem