Design Pattern in Kotlin — Factory Method

What is Factory Method Pattern?
Factory Method Pattern is a creational design pattern that Define an interface for creating an object, but let subclasses decide which class to instantiate. Factory Method lets a class defer instantiation to subclasses.
Factory Method Pattern literally is a factory. It is used to produce objects according to our requirements.
In Factory Method Pattern, we create objects without revealing the logic of creating objects on the user side and referring to new objects created using the generic interface.
And Factory Pattern is used when there is a superclass with multiple subclasses, based on the input and must return one of those subclasses.
What basic components does it have?
Super Class: It could be an interface, abstract class or normal class.
Sub Classes: include classes that implement methods of Super Class.
Factory Class: The class is responsible for creating sub classes. This class is usually Singleton or a normal class provides a public static method .
We have the following example:

Super Class:

Sub Classes:


Factory class:

ComputerType:

Client:

And we have the output of the above code:

Thanks for taking the time for me :D
Good bye and see you next.
