Chapter 4 - Design Patterns Flashcards
Which kinds of Patterns are there?
Idioms: Usage of programming language features, Design Patterns: teams of interacting objects and classes, Architecture Patterns: building blocks of software architecture
What is good Class Design?
minimize visibility of classes and members (private as default), minimize mutability, single responsibility (class should only do one thing), naming (simple & expressive names)
What is SOLID?
SRP, OCP, LSP, ISP, DIP
What is SRP?
Single Responsibility Principle: separation of concerns, changes to a class should have only a single reason
What is OCP?
Open-Closed Principle: classes closed for modifications, but open for extensions
What is LSP?
Liskov Substitution Principle: derived class must fulfill the contract of its base class
What is ISP?
Interface Segregation Principle: clients should not depend on interfaces they don’t need, if possible many small interfaces instead of one big
What is DIP?
Dependency Inversion Principle: high level components should not depend on low-level components, changes in lower level must not impact higher layers
what is the motivation of design patterns?
reuse is a main incentive, design can be best reused of all thing
Name types of Design Patterns
creational patterns: encapsulate creation process, Structural patterns: compositions of classes and objects, Behavioral Patterns: how do objects work together? collaboration patterns
Define the Singleton Pattern
ensure that there is only a single instance of a class, provides global access point to this instance
Define Factory Method
defines interface for creating an object, subclass decides what objects are being created
Define Abstract Factory
provides an interface for creating families of related or dependent objects without specifying their concrete classes
Define Adapter
convert interface of a class into an interface expected by clients (also known as Wrapper)
Define Bridge
decouple abstraction from its implementation such that both can vary independently, avoid strong coupling between abstraction and implementation