Now, using the abstract factory pattern, we can organize and structure the code so the responsibility of creating the objects are encapsulated in the Factories.
Take a look at the code 👀
If you run the project, the output will be the following:
MacOs Factory starting...
Creating an alert box that works on MacOs
> The MacOs alert box is now displayed
This is a button that works on MacOs
> The MacOs button is now displayed
Linux Factory starting...
This is an alert box that works on Linux
> The Linux alert box is now displayed
This is a button that works on Linux
> The Linux button is now displayed
Windows Factory starting...
This is an alert box that works on Windows
> The Windows alert box is now displayed
This is a button that works on Windows
> The Windows button is now displayed
And if we draw the has a arrows 👇
ConcreteFactory1createsConcreteProductA1 andConcreteProductB1ConcreteFactory2createsConcreteProductA2 andConcreteProductB2ConcreteFactory3createsConcreteProductA3 andConcreteProductB3
You can run the console application to see the output in the console.
To do that, you can use your IDE buttons/options or via terminal, executing the following command:
before executing the command,
cdto this repository root directory
dotnet run --project ./AbstractFactoryPattern/AbstractFactoryPattern.WithPattern/AbstractFactoryPattern.WithPattern.csproj
