Week 5 Flashcards
How does the Factory Design Pattern separate responsibility/details for creating an instance?
It separates the responsibility/details for creating an instance from the class that uses the instance.
The factory design pattern uses 2 interfaces/abstract classes. How do they work?
One is used to create the object, the other is used to interact with the object.
What Java class have we used recently that utilizes the Factory pattern?
DriverManager.
Explain how DriverManager works as a factory
DriverManager can create instances of connections to DBs.
DriverManager manages a list of ‘drivers’ registered. What iterates through the registered driver to crreate and return the connection to the caller?
getConnection()
T/F - You can have multiple drivers per type of DB
False. 1 per DB (MySQL, Oracle)
Files.____________() uses the factory design pattern to create an inputStream object to read a files content.
Files.newInputStream()
How does Abstract Factory Design differ from Simple Factory Design? What advantage does it offer?
Abstract can create different but related objects, like several different types of calculators.
Other than that it also abstracts further.
Factory and Builder are both creational DPs that encapsulate internal representation and construction steps.
How do Factory and Builder differ?
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