-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMemento.kt
55 lines (43 loc) · 866 Bytes
/
Memento.kt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
package design_patterns
/**
*
* pattern: Memento
*
* allows without violating encapsulation, to fix and save the state of an object
* in such a way as to restore it to this state
*
*/
class Bundle(val str: String)
/**
*
* Android system emulating
*
*/
class AndroidSystem {
private var bundle: Bundle = Bundle("")
fun saveBundle(bundle: Bundle) {
this.bundle = bundle
}
fun restoreBundle() = bundle
}
/**
*
* TextView is an Android component that draws text on the screen
*
*/
class TextView1 {
private var text: String = ""
fun setText(text: String) {
this.text = text
}
fun text() = text
fun draw() {
println(text)
}
fun onSaveInstanceState(): Bundle {
return Bundle(text)
}
fun onRestoreInstanceState(bundle: Bundle) {
text = bundle.str
}
}