Summarizing Key Findings
00:00 Now that you have gone through the advanced implementation of the Factory Method pattern, what are the key findings? Well, let’s recap the basic implementation where the client had a problem, client wanted to serialize data but didn’t know how.
00:16
Client then established an interface with the creator via the serialize()
function, which took song and data format as input parameters. The creator is a function in the basic implementation, and it makes sure that the _serialize_to_json()
and _serialize_to_xml()
product functions are executed to the benefit of the client.
00:41 But there was no clear factory method.
00:45
The advanced implementation still has the same interface. So for the client, the interface does not change. It is still the serialize()
function, which takes a song or book, and data_format
as an input parameter.
01:00
The creator, however, is now a class, and it’s not just a class. It’s a class that inherits from an abstract class called the CreatorBluePrint
.
01:10
And that creator now has a clearly defined factory method. And a factory method makes sure that the client now receives instances of the _JSONSerializer
and _XMLSerializer
classes.
01:26 So the advanced implementation is far more object-oriented, far more flexible, and easier to maintain.
01:34 So in summary, the products were changed from functions to classes, and that allowed for more flexible client code. The creator was also converted to a class, and that enabled you to build in some extra functionality.
01:50 Remember, you added some text to the output that said something nice to the client and confirmed the type of data format that was being used, and then showed the output.
02:02
You implemented abstract classes and protocols to bring consistency. Remember, abstract classes used inheritance, whereas Protocol
did not use inheritance.
02:13 And then finally, you implemented a product register and that made maintenance less cumbersome. You might remember that adding the YAML product only required a few lines of code.
02:27 If you think back all the way to the start of the course to the conditional code that you wrote back then and the challenges that that code represented, do you agree that those challenges have been addressed by the Factory Method design pattern?
02:43 Is your code more understandable and readable now? Well, I think that’s questionable because the initial code didn’t really have complex conditional code.
02:53
It only had one elif
. So a more complex example would prove this point more strongly.
03:02 Is your code more maintainable now? Well, I think that is a very clear yes, because with only a few lines of code were you able to add the client objects.
03:13
For example, you added the Book
class and with a few lines of code, you change the existing client objects. So remember the Song
class where you added playlists as an attribute? And with only a few lines of code, you added a new format.
03:28 Remember YAML, and ultimately, you let the creator manage the product creation, so separate from the client code, and that goes back to a key point of the Factory Method design pattern to separate the client code from the object creation.
03:47 So after quite a journey, you have achieved what you set out to do: to create understandable, readable, and maintainable code that separates the client code from the object creation.
04:00 And I think that’s an amazing achievement, so many congratulations. So all that’s left to do is to please join me in the next lesson to complete the course.
Become a Member to join the conversation.