Skip to content

Commit 2392ff4

Browse files
committed
Facade: Refactoring
1 parent 225e405 commit 2392ff4

File tree

1 file changed

+9
-8
lines changed

1 file changed

+9
-8
lines changed

src/test/kotlin/Facade.kt

+9-8
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,28 @@
1-
import java.util.*
1+
class ComplexSystemStore(private val filePath: String) {
22

3-
class ComplexSystemStore(val filePath: String) {
3+
private val cache: HashMap<String, String>
44

55
init {
66
println("Reading data from file: $filePath")
7+
cache = HashMap()
8+
//read properties from file and put to store cache
79
}
810

9-
val store = HashMap<String, String>()
10-
1111
fun store(key: String, payload: String) {
12-
store.put(key, payload)
12+
cache[key] = payload
1313
}
1414

15-
fun read(key: String): String = store[key] ?: ""
15+
fun read(key: String): String = cache[key] ?: ""
1616

17-
fun commit() = println("Storing cached data: $store to file: $filePath")
17+
fun commit() = println("Storing cached data: $cache to file: $filePath")
1818
}
1919

2020
data class User(val login: String)
2121

2222
//Facade:
2323
class UserRepository {
24-
val systemPreferences = ComplexSystemStore("/data/default.prefs")
24+
25+
private val systemPreferences = ComplexSystemStore("/data/default.prefs")
2526

2627
fun save(user: User) {
2728
systemPreferences.store("USER_KEY", user.login)

0 commit comments

Comments
 (0)