Quiz 2 Flashcards
List the 4 common design patterns.
- Singleton
- Factory
- Observer
- Adapter
Purpose of ‘Factory’ design pattern?
Provides an interface for creating objects in a superclass, but allows subclasses to alter the type of objects that will be created.
Purpose of ‘Singleton’ design pattern?
ensures that a class has only one instance, while providing a global access point to this instance.
Purpose of ‘Observer’ design pattern?
lets you define a subscription mechanism to notify multiple objects about any events that happen to the object they’re observing.
Purpose of ‘Adapter’ design pattern?
Allows objects with incompatible interfaces to collaborate.
what are the three categories of design patterns?
- Creational
- Structural
- Behavioural
What is the ‘SOLID’ principle?
- Single Responsibility Principle (high cohesion, low coupling)
- Open/Closed Principle
- Liskov Substitution Principle
- Interface Segregation Principle
- Dependency Inversion Principle
What is the Single Responsibility principle?
A class should have only a single responsibility.
What is Open/Closed Principle?
A class must be closed for internal change but open for extension.
What is Liskov Substitution Principle?
Objects of a supertype in a program may be replaced with objects of a subtype without altering any desirable properties of the program.
What is Dependency Inversion Principle?
Depends on abstractions on implementations.
What is Interface Segregation Principle?
No client should be forced to depend on methods it does not use.
What is the difference between ‘technical debt’ and ‘code smell’?
Technical debts are choices that are done for fast initial gains but are counterproductive in long term.
Code smells are signs of weak designs and coding.