1 / 17

Das Command Muster

This document explores the implementation of the Command Pattern in Java, focusing on managing remote control operations. It demonstrates how commands can be decoupled from their execution using interchangeable button commands. The example includes classes for Light control and an EntranceGate, illustrating the creation and execution of commands. Furthermore, it highlights a SimpleRemoteControl that can execute commands upon button presses, using a test scenario to validate functionality. The material also covers diagrammatic representation and additional functions, like "undo".

coyne
Télécharger la présentation

Das Command Muster

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Das Command Muster Deimbacher, Gölles

  2. Fakten • Verhaltensmuster • GoF – Muster • Auslösender und Ausführender sind entkoppelt.

  3. Die Fernbedienung ON-Knopf 1 OFF-Knopf 1 Rückgängig Knopf

  4. Austauschbare Befehle • Die Geräte die gesteuert werden sind verschieden

  5. Command publicinterface Command { publicvoidexecute(); }

  6. Licht an… publicclassLightOnCommandextends Command { private Light light; publicLightOnCommand(Light light) { this.light = light; } publicvoidexecute() { light.on(); } } Bei Ausführung wird Licht eingeschalten

  7. Fernbedienung • publicclassSimpleRemoteControl{ • private Command slot; • publicSimpleRemoteControl() {} • publicvoidsetCommand(Command command) { • slot = command; • } • publicvoidbuttonWasPressed() • { • slot.execute(); • } • }

  8. Testen der Fernbedienung • public class RemoteControlTest { • publicstaticvoid main(String[] args) { • SimpleRemoteControlremote = newSimpleRemoteControl(); • Light light = new Light(); • LightOnCommandlightOn = newLightOnCommand(light); • remote.setCommand(lightOn); • remote.buttonWasPressed(); • } • } Erstellen der benötigten Objekte Zuweisung des Licht-An-Befehl

  9. Aufgabenstellung • Implementiere den Befehl (Command) • Zeichne das dazugehörige Klassendiagramm Öffnen des Tores Es existiert eine Klasse „EntranceGate“

  10. Auflösung publicclassOpenEntraceGateCommandextendsCommand { privateEntraceGategate; publicOpenEntraceGateCommand(EntraceGategate){ this.gate= gate; } publicvoidexecute() { gate.openGate(); } }

  11. Mehr Buttons, mehr Funktionen

  12. Rückgängig Funktion… Rückgängig Knopf

  13. Gesamte Klassendiagramm

  14. Erstellen des „ConreteCommand“ • Schnittstelle für Befehle • FuehreAus() – Fürt Funktion aus • Besitzt Befehl (Befehle) • Ruft Befehl auf • Weiß wie die Arbeit funktioniert • Kann jede Klasse sein • Verbinden Action und Receiver

  15. Weitere Anwendungsfälle

  16. Weitere Anwendungsfälle

  17. Vielen Dank für eure Aufmerksamkeit Deimbacher, Gölles

More Related