Determine When to Use Design Patterns Flashcards

1
Q

What is a Design Pattern?

A

A Design Pattern is like a standard that is universally agreed upon to help streamline code development. This helps you to write code that will accomplish exactly what you want it to accomplish.

Design patterns are to programming like the “Hero’s Journey” is to stories/tales; an archetype or series of plot points that your program will go through.

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

Is a Design Pattern code?

A

NO - A design pattern is NOT code… a Design Pattern is a set of rules about how you can write code.

You can apply a design pattern to any language that you want to program in.

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

What is a Singleton Design Pattern?

What is an example?

A

A pattern that restricts classes to only being instantiated ONE TIME during the execution of the program.

Each class creates a SIGNLE instance/object.. If you need to create new ones, it will just refer back to the first object that was created from the class.

○ Ex - program values that you need to execute one time when the program boots up, and then once running the code just uses that instance from now on

○ Ex - static values you want referenced throughout your program

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

What is an Observer Design Pattern?

What is an example?

A

A pattern that allows multiple/different things (Observers) to receive updates or notifications when a single source (Subject) changes.

Very popular in UI systems and/or Event Updates.

EX - you have text boxes on one side and a chart on the other. Each time one of the text boxes is updated (Subject Object) the chart on the other side updates (Observer Object).

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

What are the 2 Classes that are defined by an Observer Pattern?

A

Subject Class and Observer Class

Subject Class - maintains a list of observers and includes methods for attaching, detaching, and notifying observers.

Observer Class - method to receive updates from the subject.

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

Is an Observer to Subject Class relationship 1:1?

A

NO - an Observer can be subscribed to many different Subjects; loosely coupled.

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

What is a Model View Design Pattern?

A

Very popular design patter that’s come about in recent years (since 2005); it’s really good for web development

A high-level abstraction where responsibilities are divided up into 3 loosely coupled components – the Model, the View, and the Controller.

○ Each component has different responsibilities – you can work on the different components at different times or in parallel

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

What is the “Model” in the MVC Design Pattern?

A

The component that stores or structures data.

EX - If you have a list of users in your application and those users need to be displayed on screen, the model is the Class that represents those users inside of the program.

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

What is the “View” in the MVC Design Pattern?

A

The component that displays the data; responsible for showing the data on the users screen.

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

What is the “Controller” in the MVC Design Pattern?

A

The component that handles the logic flow, handles any user interactions, and directs the Models and Views.

○ Ex - if a user clicks the search button on a View, the controller receives that event and it will direct the Model and the View to perform the search and update with the new data that resulted from the search

Basically:
○ Responds to user events/inputs
○ Tells the other 2 components (Model and View) what to do

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

Design Pattern Summary

A

→ Design patterns represent:
○ Tried and tested solutions within your code

○ Apply framework aka “scaffolding” for new code i.e code doesn’t have to be written from scratch each time

○ Supports communication between developers – if you understand the universal/accepted design pattern behind code, it will help you quickly understand what that code is supposed to do

→ Design patterns can communicate the intent of code to someone reading it for the first time

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