- When a method returns one of several possible classes that share a common super class
- Create a new enemy in a game
- Random number generator picks a number assigned to a specific enemy
- The factory returns the enemy associated with the number
- The class is chosen at run time
- When you don't know ahead of time what class object you need
- when all of the potential classes are in the same subclass hierarchy
- To centralize class selection code
- When you don't want the user to have to know every subclass
- To encapsulate object creation
- When you need many other objects to receive an update when another object changes
- Examples:
- Stock market with thousands of stocks need to send updates to objects representing individual stocks
- The Subject (publisher) sends many stocks to the Observers
- The Observers (subscribers) taken the ones they want and use them
- Examples:
- Loose coupling is a benefit
- The Subject (publisher) doesn't need to know anything about the Observers (subscribers)
- Negatives: The Subject (publisher) may send updates that don't matter to the Observer (subscriber)
- When you need many other objects to receive an update when another object changes
- Examples:
- Stock market with thousands of stocks need to send updates to objects representing individual stocks
- The Subject (publisher) sends many stocks to the Observers
- The Observers (subscribers) taken the ones they want and use them
- Examples:
- Loose coupling is a benefit
- The Subject (publisher) doesn't need to know anything about the Observers (subscribers)
- Negatives: The Subject (publisher) may send updates that don't matter to the Observer (subscriber)


