Week 5 Flashcards

1
Q

How does the Factory Design Pattern separate responsibility/details for creating an instance?

A

It separates the responsibility/details for creating an instance from the class that uses the instance.

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

The factory design pattern uses 2 interfaces/abstract classes. How do they work?

A

One is used to create the object, the other is used to interact with the object.

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

What Java class have we used recently that utilizes the Factory pattern?

A

DriverManager.

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

Explain how DriverManager works as a factory

A

DriverManager can create instances of connections to DBs.

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

DriverManager manages a list of ‘drivers’ registered. What iterates through the registered driver to crreate and return the connection to the caller?

A

getConnection()

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

T/F - You can have multiple drivers per type of DB

A

False. 1 per DB (MySQL, Oracle)

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

Files.____________() uses the factory design pattern to create an inputStream object to read a files content.

A

Files.newInputStream()

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

How does Abstract Factory Design differ from Simple Factory Design? What advantage does it offer?

A

Abstract can create different but related objects, like several different types of calculators.

Other than that it also abstracts further.

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

Factory and Builder are both creational DPs that encapsulate internal representation and construction steps.

How do Factory and Builder differ?

A

Factory can create an object in a single method call (often static). Can be thought of as a wrapper for a constructor.

Builder creates objects using multiple method calls,often using chaining

Builder permits optional features and/or deaults

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