90 likes | 170 Views
STRATEGY. Object Behavioral Pattern. You are at the Pub two weeks before Fall Formal and still don’t have a date! All of a sudden a girl who you had a crush on during o-week walks in.
E N D
STRATEGY Object Behavioral Pattern
You are at the Pub two weeks before Fall Formal and still don’t have a date! All of a sudden a girl who you had a crush on during o-week walks in There are many different ways that you could approach this situation. Each approach requires a different methodology, but achieves the same goal (i.e. you have confronted your crush)
Do you believe in love at first sight or should I walk around the room again?
Intent of Strategy • Define a family of algorithms, encapsulate each one, and make them interchangeable • Strategy provides a common interface for all encapsulated algorithms and allows the algorithm to vary independently of the client
When is Strategy used? • When many related classes differ only in their behavior • Different variants of an algorithm exist in order to reflect different space/time trade-offs
Airline Ticket Reservations • There are many different ways to obtain an airline ticket. Depending on your utility for time and money, you may be looking for the cheapest flight available or you might want to find the quickest flight to your destination.