design patterns Flashcards
what are design patterns
reusable solutions to common problems that occur in software design
what are the 4 elements of a design pattern
name; description of the pattern in 2 or less words
problem; when you should use the pattern
solution; elements that make up the design and interactions responsibilities and relationships
consequences; trade offs of using the pattern
what are the 3 categories of design patterns
creational; techniques to create objects
structural; how classes are imposed in larger structures
behavioural; communication between objects
what is the observer design pattern
behavioural design pattern that allows you to define a subscription mechanism to notify other objects about any changes made in the object their observing
subject/publisher
the object that is changing state and informs observers
observers/subscribers
dynamically attached to the subject and can subscribe to event notifications
subject as an abstract class
abstract class defines add remove and notify observers
the concrete subject extends the abstract class
the concrete observer implements the observer interface and registers with concrete subjects to receive updates
subject as an interface
can add remove and notify observers
the concrete subject implements this and keeps a list of the observers and notifies them
the concrete observer implements the observer interface and registers with concrete subjects to receive updates
what is an adaptor design pattern
structural design pattern that converts the interface of a class into an interface that the client expects
what are the 4 classes needed for the adaptor
client; who wants to use the interface
target; the interface that the client uses
adaptor; adapts the adaptee to the target interface
adaptee; the existing interface that needs changing
class adaptor
adaps the adaptee by inheriting it and implementing the target interface
object adaptor
relies on composition
the adaptor implements the target interface and contains the adaptee instance to which it forwards the request