Intro to Design Patterns - OOP Flashcards
Software design pattern
Reusable patterns commonly used to solve problems. Usually describes how classes and functions are structured and used. Usually conceptual and language-agnostic.
What are Design Patterns?
Software design patterns are reusable patterns that usually guide how class and functions are structured and used.
Iterator
A class whose responsibility is to know how to iterate through an object.
Factory
A class or method whose responsibility is to create instances of some class.
Adapter
A class whose responsibility is to help two other classes communicate with each other.
Observer
A class whose responsibility is to watch for changes over many objects, and notify many objects when changes happen.
Decorator
A class or method whose responsibility is to dynamically alter and extend the behavior of a function or class.
Strategy
A class whose responsibility is to represent an algorithm.
How Do We Use design patterns?
Design patterns are applied when it makes problem-solving easier. It takes time, experience, research, context, and experimentation to apply design patterns effectively.
When considering a design pattern, the team should consider:
Does this make the code more or less maintainable over time?
What is the cost of implementing this design pattern?
What are the benefits of implementing this design pattern?
What are the alternatives?