OOP Factories
Lesson Objectives
Create a Factory
Bonus - static properties for a class
Create a factory
Sometimes we need to have a factory object that will generate other objects
The purpose of the factory is so it can control the creation process in some way
This is usually a single object that exists throughout the program that performs a set of functions
also called a singleton
Let's start with a car
Now let's make a factory class that will make cars for us.
Now we can easily create another new factory that produces its own cars
Extra
Create static properties for a class
Sometimes you want to define properties that pertain to the class as a whole, not the instance. This allows us to limit, somewhat, what the user of class can do.
Adapted from SEI-MAE
Last updated
Was this helpful?