itec 370 lecture 12 design. review questions? design patterns –how useful are they? –command...

14
ITEC 370 Lecture 12 Design

Upload: everett-walsh

Post on 15-Jan-2016

216 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: ITEC 370 Lecture 12 Design. Review Questions? Design patterns –How useful are they? –Command pattern What is it? What can it do for you?

ITEC 370

Lecture 12Design

Page 2: ITEC 370 Lecture 12 Design. Review Questions? Design patterns –How useful are they? –Command pattern What is it? What can it do for you?

Design

Review

• Questions?• Design patterns– How useful are they?– Command pattern• What is it?• What can it do for you?

Page 3: ITEC 370 Lecture 12 Design. Review Questions? Design patterns –How useful are they? –Command pattern What is it? What can it do for you?

Design

Objectives

• Design patterns– A few good ones

Page 4: ITEC 370 Lecture 12 Design. Review Questions? Design patterns –How useful are they? –Command pattern What is it? What can it do for you?

Design

Review

• Design patterns• Command pattern– Definition– Example

Page 5: ITEC 370 Lecture 12 Design. Review Questions? Design patterns –How useful are they? –Command pattern What is it? What can it do for you?

Design

Adapter

• Square peg, round hole problem• Use aggregation or inheritance• Pass-through for a system• Example

Page 6: ITEC 370 Lecture 12 Design. Review Questions? Design patterns –How useful are they? –Command pattern What is it? What can it do for you?

Design

Bridge

• Two software parts, and a desire to not strongly couple them

• Class A / Class B• A and B only interact with each other

using class C• Only C has to be changed if A/B

changes• Examples

Page 7: ITEC 370 Lecture 12 Design. Review Questions? Design patterns –How useful are they? –Command pattern What is it? What can it do for you?

Design

Factory

• Used to create instances of a class– Not just a constructor

• Many variants– Static interfaces– Separate class (similar to a bridge)

• Goal– Have something that takes information

and returns a class that can be used– DB entry

Page 8: ITEC 370 Lecture 12 Design. Review Questions? Design patterns –How useful are they? –Command pattern What is it? What can it do for you?

Design

Flyweight

• Bookmark or easily recognizable piece of information

• Goal: create one and use it everywhere– NULL– Leaves on a tree

• Memory saver

Page 9: ITEC 370 Lecture 12 Design. Review Questions? Design patterns –How useful are they? –Command pattern What is it? What can it do for you?

Design

Facade

• Used to hide the gory details from the end user

• Abstraction layer• Many functions combined into one– Depends on what the API requires

• Lego Robot example

Page 10: ITEC 370 Lecture 12 Design. Review Questions? Design patterns –How useful are they? –Command pattern What is it? What can it do for you?

Design

Observer

• Notification pattern• One source of events• Many classes interested in said

events• When one happens, they are

informed from it• How would you design this

functionality?

Page 11: ITEC 370 Lecture 12 Design. Review Questions? Design patterns –How useful are they? –Command pattern What is it? What can it do for you?

Design

Memento

• Saves information so it can be restored later

• Create a save function• Create a recall function• Self contained or use an archive

class• Undo

Page 12: ITEC 370 Lecture 12 Design. Review Questions? Design patterns –How useful are they? –Command pattern What is it? What can it do for you?

Design

Strategy

• Task–Multiple algorithms to accomplish this

task– Pick one at run-time– How/Why?

• JVM

Page 13: ITEC 370 Lecture 12 Design. Review Questions? Design patterns –How useful are they? –Command pattern What is it? What can it do for you?

Design

Chain of responsibility

• Mimic chain of command• One class multiple choices• Based on the “ranking” of an action,

a particular choice• Example– Threat level of an warning/error

Page 14: ITEC 370 Lecture 12 Design. Review Questions? Design patterns –How useful are they? –Command pattern What is it? What can it do for you?

Design

Review

• Design patterns