Design Patterns Flashcards

1
Q

What is a design pattern?

A

A design pattern is a general, reusable solution to a commonly occuring problem within a given context.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What are the 3 categories of design patterns?

A

Creational, Structural, Behavioural.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What is MVC?

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What problem does the singleton design pattern try to solve?

A

To ensure that a class has just a single instance and provide a global access point to that instance.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Describe how the singleton design pattern could be implemented in C#?

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What is a strategy design pattern?

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What is the decorator design pattern?

A

It attaches additional responsibilities to an object dynamically. This pattern provide a flexible alternative to subclassing for extending functionality.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What problem does the factory method pattern attempt to solve? How is it implemented in C#

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What are creational design patterns?

A

Creational patterns provide various object creation mechanisms, which increase flexibility and reuse of existing code.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

What are Structural design patterns?

A

Structural patterns explain how to assemble objects and classes into larger structures while keeping these structures flexible and efficient.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

What are behavioural design patterns?

A

Behavioural design patterns are concerned with algorithms and the assignment of responsibilities between objects

How well did you know this?
1
Not at all
2
3
4
5
Perfectly