object DatabaseConnection { this: LoginDevice =>
val Connection = ...
class LoginDevice {
val prep = Connection.prepareStatement("SELECT * FROM USER WHERE NAME = ?")
def login(username: String, password: String) = {
prep.setString(1, username)
val rs = prep.executeQuery
if (!rs.next)
throw User404
new User(rs.getString("Name"), ...)
}
}
}
object RequestHandler {
type Request = (String, String)
def handle(request: Request) = request._1 match {
case "Login" => {
val info = request._2.split(",")
DatabaseConnection.login(info(0), info(1)) // SYNTAX ERROR
}
case _ => throw new Exception("Request type is not valid.")
}
}
现在,我想将我的 DatabaseConnection 拆分为具有自己准备好的语句等的“设备”。Connection
不过,它们都应该引用这个实例。我希望能够从外部调用内部函数。
无需重命名任何这些功能的最佳方法是什么?
顺便说一句,对于短文本,我的手在自动取款机上是真的被禁用了。