Design Patterns Practice Exam
Question 1 of 50
Strategy
if/else
TCPConnection
Established
Listening
Closed
switch
abstract class DataParser { final void parse() { openFile(); readData(); // abstract closeFile(); }}
abstract class Creator { abstract Product factoryMethod();}
OrderService → MySQLDatabase
OrderService → DatabaseInterface ← MySQLDatabase
context.setStrategy(new QuickSortStrategy());context.executeStrategy(data);
element.accept(visitor);// inside: visitor.visit(this);
Pizza pizza = new Pizza.Builder() .size("large") .cheese(true) .pepperoni(true) .build();
interface Command { void execute(); void undo();}
Prototype clone = original.clone();
Shape
Color
RedCircle
User
UserAuthenticator
UserRepository
EmailService
BufferedReader(InputStreamReader(FileInputStream))
subject.addObserver(observer);subject.notifyAll();
interface GUIFactory { Button createButton(); Checkbox createCheckbox();}
File
Directory
FileSystemComponent
interface Component { void operation();}class Leaf implements Component {...}class Composite implements Component {...}
Square extends Rectangle
Iterator<Item> it = collection.iterator();while (it.hasNext()) { Item item = it.next();}
public static Singleton getInstance() { if (instance == null) instance = new Singleton(); return instance; }
RoadLogistics
Truck
SeaLogistics
Ship
Transport
handler1.setNext(handler2);handler2.setNext(handler3);handler1.handle(request);
HomeTheaterFacade
watchMovie()
interface Worker { void work(); void eat(); }
interface Workable { void work(); }interface Feedable { void eat(); }
new BufferedInputStream(new FileInputStream("file.txt"))
Question navigator