TypeScript Design Patterns

TypeScript Design Patterns

memorize.aimemorize.ai (lvl 286)
Section 1

Preview this deck

When is the builder design pattern useful?

Front

Star 0%
Star 0%
Star 0%
Star 0%
Star 0%

0.0

0 reviews

5
0
4
0
3
0
2
0
1
0

Active users

0

All-time users

0

Favorites

0

Last updated

7 years ago

Date created

Mar 1, 2020

Cards (44)

Section 1

(44 cards)

When is the builder design pattern useful?

Front

This design pattern is useful when you can separate the construction of an object from its representation. This allows for multiple options in the creation of the object.

Back

When is using the facade design pattern useful?

Front

This design pattern is useful when you have a single class that represents an entire subsystem. The client gives all the inputs and then all the operations are taken care of behind the scene. It represents the transactional boundary.

Back

When is using the flyweight design pattern useful?

Front

This design pattern is useful when you need a fine grained instance for efficient sharing.

Back

What are the types of behavioral design patterns?

Front

1. Chain of Responsibility 2. Command 3. Memento 4. Iterator 5. Mediator

Back

When is using the iterator design pattern useful?

Front

This design pattern is useful when you need to sequentially access the elements of a collection.

Back

When is using the adapter design pattern useful?

Front

This design pattern is useful when you need to match interfaces from different classes.

Back

What is an example of using the builder design pattern?

Front

This design pattern could be used when building a multi-course dinner which includes: - Drinks - Starters - Main Course - Desert There are multiple ways people could organize the dinner with any combination of 1 to 4 parts.

Back

What are advantages of using the facade design pattern?

Front

Advantages of this design pattern are: - Reduce network calls - Reduce coupling

Back

What is an example of using the decorator design pattern?

Front

This design pattern could be useful when: - Managing types of pizza. There could be 10 types of pizza with 3 types of toppings (30 classes). - Adding a discount to an order.

Back

What is an example of using the observer design pattern?

Front

online bidding

Back

When is the singleton design pattern useful?

Front

This design pattern is useful when you have a class of which only a single instance can exist.

Back

What is an example of using the prototype design pattern?

Front

This design pattern should be used in a chess game for the initial setup. Instead of generating the initial setup every time, initialize the game once and clone that instance whenever a game needs to restart.

Back

When is using the state design pattern useful?

Front

This design pattern is useful when the behavior of an object needs to change when its state changes.

Back

What are some examples of SOLID principles?

Front

1. Single responsibility 2. Open-closed 3. Liskov substitution 4. Interface segregation 5. Dependency inversion

Back

What are the types of structural design patterns?

Front

1. Composite 2. Decorator 3. Adapter 4. Bridge 5. Facade 6. Flyweight 7. Proxy

Back

When is using the observer design pattern useful?

Front

This design pattern is useful when you need to notify many classes of a change in one class. The two important parts are registration and notification.

Back

What should you be aware of when creating singletons?

Front

- Constructor should be private - Build with an enum (in Java, what about Typescript?)

Back

When is the prototype design pattern useful?

Front

This design pattern should be used if you have a fully initialized instance that needs to be copied or cloned.

Back

What is an example of using the iterator design pattern?

Front

This design pattern could be used for next and previous buttons on a remote control.

Back

What is an example of using the strategy design pattern?

Front

[Different sorting algorithms]

Back

When is using the visitor design pattern useful?

Front

Restrict users from editing the code API, but extending it

Back

What is an example of using the facade design pattern?

Front

This design pattern could be used for: - Event Manager - Online Book ordering

Back

What is an example of using the singleton design pattern?

Front

This design pattern could be used for a president of a country. There can only be one president at a time.

Back

What are patterns and architecture in JavaScript and TypeScript?

Front

1. Promise-based web architecture 2. Modularizing project 3. Asynchronous patterns.

Back

What is an example of using the proxy design pattern?

Front

This design pattern could be useful when managing a debit card (the proxy for a bank account). The real object is the bank account.

Back

What is an example of using the factory design pattern?

Front

This design pattern could be useful for creating people, which have extended classes of male and female.

Back

When is the proxy design pattern useful?

Front

This design pattern is useful when you have an object representing another object. This design pattern is able to hide complexity.

Back

What are the types of creational design patterns?

Front

1. Factory Method 2. Abstract Factory 3. Builder 4. Prototype 5. Singleton

Back

What is an example of using the state design pattern?

Front

This design pattern could be used for: - Fan speed controls which change the speed of the blades

Back

What are SOLID principles?

Front

[S] Single responsibility principles [O] Open-closed principle [L] Liskov substitution principle [I] Interface segregation principle [D] Dependency inversion principle

Back

What are disadvantages of using the singleton design pattern?

Front

This design pattern makes unit testing difficult

Back

What terms describe a design pattern?

Front

1. Participants 2. Pattern Scope 3. Implementation 4. Consequences

Back

What is a disadvantage of using the decorator pattern?

Front

- Higher complexity creating objects

Back

What is an example of using the flyweight design pattern?

Front

This design pattern could be used for: - Public switched telephone network. Efficiently manage a network of 1000 users and 10 lines since all users will not use the lines at the same time. - Connection Pools

Back

What are patterns and architectures in JavaScript and Typescript?

Front

1. Promise-based web architecture 2. Modularizing project 2. Asynchronous patterns

Back

What is the difference between a behavioral design pattern and a continuous behavioral design pattern?

Front

[answer]

Back

When is using the decorator design pattern useful?

Front

This design pattern is useful when we want to add responsibilities to objects dynamically (at run time). This approach can be used instead of inheritance, where responsibilities are added statically.

Back

What is an example of using the chain of responsibility design pattern?

Front

This design pattern could be used for: - Exception handling system. The system looks for a try catch block by going backwards in the code. - Loan Approval process. Each person with higher level has a little more power to adjust the loan.

Back

When is using the strategy design pattern useful?

Front

This design pattern is useful when you need to encapsulate an algorithm within a class.

Back

What is a disadvantage of using the decorator pattern?

Front

Back

What are the benefits of using the builder design pattern?

Front

- Code is easier to read - Simplifies the creation process

Back

What are the types of continuous behavioral design patterns?

Front

1. Strategy 2. State Pattern 3. Template Method 4. Observer 5. Visitor

Back

What is an example of using the adapter design pattern?

Front

This design patterns could be used for: - Phone power adapters - Converting Java into JSON or XML

Back

When is the factory design pattern useful?

Front

This design pattern is useful when creating a family of objects.

Back