I have a doubt about the Factory
pattern and particularly on the question #5 in the self
test.
First I would like to understand if I understand the operation of the Factory pattern.
The main problem, that the use of the pattern tries to solve, is related to the change we want to do to a class to add functionality, in this case a change would also involve changing the main class.
To solve the problem the main class must only interact with an interface or an abstract class so that it does not interact with the class that takes care of the implementation.
This is an example taken from the book (K&B7):
Now we come to the question, I can not see the use of the Factory pattern in this code:
Do you help me to understand?