Factory Method Pattern - Step-by-Step

Client
VehicleFactory
(Abstract Creator)
CreateVehicle()
CarFactory
(Concrete Creator)
TruckFactory
(Concrete Creator)
IVehicle
(Product Interface)
Car
(Concrete Product)
Truck
(Concrete Product)
?

Explanation

Welcome! This animation demonstrates the Factory Method pattern step-by-step.

Goal: Define an interface for creating an object, but let subclasses decide which class to instantiate. Factory Method lets a class defer instantiation to subclasses.

Click "Start" to begin the first step. Use "Next Step" to proceed.

C# Code Snippet

// C# Code will appear here as the animation progresses.