Other factory design patterns
There are some different variations of the factory design patterns. In all cases, though, the purpose is generally the same—hide creation complexity. In the next subsections, we will briefly mention two of the other factory design patterns: static factory and simple factory.
The static factory
The static factory could be represented as a static method, which is a part of the base class. It is called to create concrete instances, which extend the base class. One of the biggest drawbacks here, however, is that if another extension of the base class is added, the base class (because of the static method) also has to be edited. Let's show a simple example from the world of the animals:
trait Animal
class Bird extends Animal
class Mammal extends Animal
class Fish extends Animal
object Animal {
def apply(animal: String): Animal = animal.toLowerCase match {
case "bird" => new Bird
case "mammal" => new Mammal
case "fish" => new Fish
case x:...