Created
November 18, 2013 18:38
-
-
Save holyjak/7532967 to your computer and use it in GitHub Desktop.
[Surfacing Hidden Design: A Better Alternative To Interrelated Mutable Fields](http://wp.me/p3ui6n-1q) - 1) Explicit and defect-preventing expression of the states and transitions - full code
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// P.S.: Excuse the underscores ... | |
class Person (val id: Int) { | |
// Simplified primitive version, assuming the information when should the evolution | |
// happen is handled somewhere else | |
def evolveHealth(): Unit = { | |
if (!_infected) | |
if (randomGenerator.randomBelow(101) <= config.transmissibilityPct) | |
this._infected = true | |
if (_infected && !_sick && !_immune) | |
this._sick = true | |
if (_sick) | |
if (randomGenerator.randomBelow(101) <= config.mortalityPct) | |
this._dead = true | |
else | |
this._unDead = true // did not die but still sick | |
if (_unDead) | |
this._immune = true | |
this._sick = true | |
if (_immune) | |
this._immune = false | |
this._infected = false | |
} | |
private var _unDead = false | |
private var _infected = false | |
private var _sick = false | |
private var _immune = false | |
private var _dead = false | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment