Design Patterns Flashcards
What is a design pattern?
A design pattern is a general, reusable solution to a commonly occuring problem within a given context.
What are the 3 categories of design patterns?
Creational, Structural, Behavioural.
What is MVC?
MVC stands for (Model view controller) it’s an software design pattern commonly used for developing user interfaces that divide the related program logic into three elements.
What problem does the singleton design pattern try to solve?
To ensure that a class has just a single instance and provide a global access point to that instance.
Describe how the singleton design pattern could be implemented in C#?
You need to declare a constructor that should be private and parameterless.
The class should be declared as sealed which will ensure that it cannot be inherited.
You need to create a private static variable that is going to hold a reference to the single created instance of the class if any.
You need to create a public static property/method which will return the single-created instance of the singleton class.
What is a strategy design pattern?
It defines a family of algorithms, encapsulate each one, and make them interchangeable. This pattern let’s the algorithm vary independently from clients that use it.
What is the decorator design pattern?
It attaches additional responsibilities to an object dynamically. This pattern provide a flexible alternative to subclassing for extending functionality.
What problem does the factory method pattern attempt to solve? How is it implemented in C#
It provides an interface for creating objects in a superclass, but allows subclasses to alter the type of objects that will be created.
It can be implemented by:
Creating a product interface
Creating classes implementing the product interface.
Create a abstract creator that declares the factory method, which returns an object of type product.
Creating a concrete creator object that overrides the factory method to return an instance of a concrete product.
What are creational design patterns?
Creational patterns provide various object creation mechanisms, which increase flexibility and reuse of existing code.
What are Structural design patterns?
Structural patterns explain how to assemble objects and classes into larger structures while keeping these structures flexible and efficient.
What are behavioural design patterns?
Behavioural design patterns are concerned with algorithms and the assignment of responsibilities between objects