// SRP( Single Responsibility Priciple) - 단일 책임 원칙
// API, Database, Decoding (Bad Case)
class LoginServiceBad {
func login(id: String, pw: String) {
let userData = requestlogin()
let user = decodeUserInfom(data: userData)
saveUserOnDatabase(user: user)
}
private func requestlogin() -> Data {
return Data()
}
private func decodeUserInfom(data: Data) -> User {
return User(name: "testUser", age: 10)
}
private func saveUserOnDatabase(user: User) {
print("User data \(user.name) are saved!!!")
}
}
class User {
var name: String
var age: Int
init(name: String, age: Int) {
self.name = name
self.age = age
}
private func toString() {
print("My Name is: \(self.name), and \(self.age) years old")
}
}