私は Java のバックグラウンドを持っていますが、予想どおり、Scala で使用されるいくつかのパターンを理解するのに問題があります (以下を参照)。Scala のパターンやプログラミングの方法論をよく理解していると感じるたびに、プログラミングの理解を超えた何かが浮かび上がり、学習モードに戻ります。これは、学び続けることを常に刺激する scala の美しさだと思います :)
とにかく、scala swing でサンプル プログラミングをしようとしています........
val frame = new MainFrame {
title = "Electronic Classroom"
contents = new BorderPanel {
layout += new GridPanel(1, 2) {
contents += new ScrollPane(semesterList)
contents += new ScrollPane(courseList)
} -> West
}
menuBar = new MenuBar {
contents += new Menu("File") {
contents += new MenuItem("Login") {
action = Action("Login"){
login
user match{
case Some(inst:Instructor) => instructorMenu.enabled = true
enabled = false
case Some(_) => instructorMenu.enabled = false
enabled = false
case _ =>
}
}
}
contents += new Separator
contents += new MenuItem(Action("Exit")(sys.exit(0)))
}
}
contents += instructorMenu
}
size = new Dimension(1000, 600)
centerOnScreen
}
ここでは、値を定義する際に def または val キーワードを使用せずに def および val に値を設定しています (タイトル、サイズ、コンテンツなど)。すべての割り当てが Java で行う方法とは異なり、ボディ スクリプトのように見えます。などはメソッド本体で行われます..ここに大きなデザインパターンが欠けていると思います
誰か助けて、Scalaのデザインパターンを説明してくれませんか??