Design Pattern Basic Flashcards

1
Q

Types of design patters

A

Creational, Structural, Behavioral

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

Creational

A

designed for class instantiation can be class or object creational patterns (e.g. singleton design)

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

Structural

A

increase functionality of the classes involved without changing much of its composition (e.g. Decorator Design)

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

Behavioral

A

take care of effective communication and the assignment of responsibilities between objects. Chain of responsibility, iterator, mediator, strategy

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

Factory

A

a class handling creation of different object (e.g. ShapeFactory which returns different shape based on the info passed in) Used when a class cannot anticipate the type of objects it needs to create before hand. Allow creation of object without knowing the details of it.

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

Abstract factory

A

A base class with abstract methods defining methods for the objects that should be created. Each factory class which derives the base class can create their own implementation of each object type.

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

Aggregation

A

child can exits independently of the parent

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

Composition

A

child cannot exist independent of the parent

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

Singleton Pattern

A
is a creational design pattern that lets you ensure that a class has only one instance, while providing a global access point to this instance.
Code becomes so tightly coupled that you can't make changes without affecting everything associated with it. It also doesn't support inheritance and can be easily broken.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

Static Class

A

only provides static methods, does not provide an object

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

Builder

A

builds complex object using simple objects step by step and use builder class to build the final object. It is a creational design pattern. (E.g. building a meal)

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

Prototype pattern

A

Creational design patter that lets you copy existing objects without making your code dependent on their classes. E.g. when you want to copy an object but the some fields is private and can’t be accessed.

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

Adapter Pattern

A

Bridge between two incompatible interface. Structural Design Pattern. E.g. MediaPlayer for MP3, MP4 files

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

Bridge Pattern

A

is a structural design pattern that lets you split a large class or a set of closely related classes into two separate hierarchies—abstraction and implementation—which can be developed independently of each other. E.g. Remote and a set of devices

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

Proxy

A

a class represents functionality of another class. It controls access to the original object. Have a concrete class and proxy class implementing same interface. The proxy class then contains the concrete class. It is a Structural design pattern. Similar to an API.

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

Facade

A

hides complexities of the system and provides and interface the client using which the client can access the system. Structural Design Patter. Provide simplified interface to complex set of classes. E.g. You call to place an order through customer services. The customer service is the Facade.

17
Q

Decorator

A

allow user to add new functionality to an existing object without altering its structure. Create a decorator class which wraps the original class and provides additional functionality. It is a Structural Pattern. E.g. Donut adding chococlate

18
Q

Lazy Initialization

A

only initialize an object when it is needed

19
Q

Chain of responsibility

A

a behavioral design pattern that lets you pass requests along a chain of handlers. Upon receiving a request, each handler decides either to process the request or to pass it to the next handler in the chain. E.g. student submit applications and it’s passed through various handler to verify eligibility

20
Q

Iterator

A

is a behavioral design pattern that lets you traverse elements of a collection without exposing its underlying representation (list, stack, tree, etc.).

21
Q

Mediator

A

is a behavioral design pattern that lets you reduce chaotic dependencies between objects. The pattern restricts direct communications between the objects and forces them to collaborate only via a mediator object.

22
Q

State

A

is a behavioral design pattern that lets an object alter its behavior when its internal state changes. It appears as if the object changed its class. E.g. Document in different state(draft, published etc)

23
Q

Strategy

A

class behavior or its algorithm can be changed at run time. Creates object representing strategy, and then have a context which will store reference to a strategy. A behavioral design pattern that lets you define a family of algorithms, put each of them into a separate class, and make their objects interchangeable.

24
Q

MVC

A

model view controller. Separate application concerns. Model represent an object, view represent visualization and controller acts on both model and view. Controller control data flow into model and update view, it contains instance to the view and the model in its class.

25
Q

What are design patterns?

A

are typical solutions to commonly occurring problems in software design. They are like pre-made blueprints that you can customize to solve a recurring design problem in your code. These patterns save time and effort by employing dynamic aspects of object-oriented programming to allow user inputs to decide what outputs are displayed by rationalizing relationships between objects

26
Q

Explain the advantages of design patterns in Java

A

Design patterns provide a templated solution that can be used in multiple projects. I find this concept useful in defining the architecture of multiple systems and customizing them rather than coding everything by hand, over and over. I can also appreciate the thoroughness of the testing done to ensure these extensions are reliable and make my job substantially faster

27
Q

Factory vs Abstract Factory

A

“The primary difference between them is as follows: a factory pattern is a method of creating a single object through inheritance, while an abstract factory pattern creates factory patterns, effectively producing families of related objects.”