lecture18_command.pdf - CSC3380 Object Oriented Design Lecture 18 The Command Pattern(and also memento Quiz Time So far we’ve covered the following

lecture18_command.pdf - CSC3380 Object Oriented Design...

This preview shows page 1 - 10 out of 27 pages.

CSC3380 Object Oriented Design Lecture 18: The Command Pattern (and also memento)
Image of page 1
Quiz Time
Image of page 2
So far we’ve covered the following patterns: Strategy Factory method Abstract Factory State Observer Adapter Composite Iterator Builder Singleton Visitor
Image of page 3
This Class The last patterns One that is complex, but valuable to a wide variety of domains
Image of page 4
Command Encapsulates an action, to be performed at a later time, or to be reversed. Turns a “verb” into a “noun”. Can be combined with the “memento” pattern to save state.
Image of page 5
Image of page 6
Example: TV Remote
Image of page 7
Code interface Command { void Execute(); } class SwitchOn implements Command { private Device currentDevice; public SwitchOn( Device d ) { currentDevice = d; } public void Execute() { currentDevice.switchOn(); } } Personally, I would pass Television to Execute instead of storing it in the command object. Less state is better.
Image of page 8
Why bother? We can implement new kinds of controller (Bluetooth, WiFi, …) We can add functions and remap buttons.
Image of page 9
Image of page 10

You've reached the end of your free preview.

Want to read all 27 pages?

  • Spring '09
  • Suptik

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern