5-17 Code improvements (refactoring)
Time | 1 h |
Web code | f32t c578 |
Difficulty | Medium |
Aufgabe 5.17 Codeverbesserungen (Refactoring)
Diese Aufgabe hat ihren Ursprung in der Programmierung von grafischen Benutzerschnittstellen (GUI = Graphical User Interface). Doch selbst ohne die hier verwendeten Funktionen und Variablen zu kennen(!), sind Sie in der Lage, den Code zu verbessern (engl. refactoring): Fügen Sie eine weitere Subroutine ein, die Sie vier Mal aufrufen.
(Diese Aufgabe soll ohne Computer gelöst werden.)
init()
{
butt1 := makeButton("OK")
setCommand(butt1, "OK")
add(butt1, panel)
addListener(butt1, myListener)
butt2 := makeButton("Abbruch")
setCommand(butt2, "CANCEL")
add(butt2, panel)
addListener(butt2, myListener)
butt3 := makeButton("Zurück")
setCommand(butt3, "BACK")
add(butt3, panel)
addListener(butt3, myListener)
butt4 := makeButton("Weiter")
setCommand(butt4, "FORWARD")
add(butt4, panel)
addListener(butt4, myListener)
}
Exercise 5-17: Code improvements (refactoring)
This task has its origins in the programming of graphical user interfaces (GUI = Graphical User Interface). But even without knowing the functions and variables used here(!), you are able to improve the code (refactoring): Add another subroutine that you call four times.
(This task is to be solved without a computer.)
init()
{
butt1 := makeButton("OK")
setCommand(butt1, "OK")
add(butt1, panel)
addListener(butt1, myListener)
butt2 := makeButton("Cancel")
setCommand(butt2, "CANCEL")
add(butt2, panel)
addListener(butt2, myListener)
butt3 := makeButton("Back")
setCommand(butt3, "BACK")
add(butt3, panel)
addListener(butt3, myListener)
butt4 := makeButton("Forward")
setCommand(butt4, "FORWARD")
add(butt4, panel)
addListener(butt4, myListener)
}
Submit your answer:
- 5-17 Code improvements (refactoring) (Python) - CodeRunner question
- 5-17 Code improvements (refactoring) (Python) - VPL activity
- 5-17 Code improvements (refactoring) (Python) - VPL question
Sample solution: Solution to 5-17 Code improvements (refactoring)