Intro
A short blog on how you can create again some football legends!
I created a factory that produces football legends by using a software design patter, one of the most used ones, the Factory Method!
Players that we miss
All the football fun's we miss some players, especially players that they did things that we couldn't imagine,
like a dribble, a shot from a long distance, an assist with some weird way and so on.
Let's see how we can re-create them and watch some magic again!
The football factory
A factory is a static method that takes optionally a number of arguments and creates instances of a certain type.
One good property of the factory method is that the client has no knowledge how the instance is
created (or doesn't even cares, just wants one instance).
What is needed for a method factory:
- an interface, this is the type that the static method returns
- a concrete implementation of the interface (we could have more than one)
- a static method that generates the desired instances
Those are the basic ingredients of the Factory Method.
In the football factory the three ingredients are mapped to the following code fragments:
- the interface (the type that the factory returns), includes just two methods for the name and the position of the legendary player
- a concrete implementation of the interface
- the static method (factory) that creates the actual instances, takes as an argument an enum (the legendary players)
- the enum that factory requires as argument (the legends!)
Let's create some legends
Let's produce some football legends from the factory!
Now we can watch some magic!
Cheers!
Top comments (0)