The patterns in this chapter harken back to the “Creational Patterns” from the original Gang of Four Design Patterns book. In that chapter of their book, the discussed a number of now famous ways you can tackle instantiating objects including Builder and Factory Method.
Pony has object-oriented features that make existing OO creational patterns applicable to the language. However, the addition of actors and Pony’s type system also lead to patterns that may be unfamiliar to OO experts. Further, Pony is a rather FP friendly language which adds still more wrinkles.
In this chapter, we will cover the Pony variants of tried and true creational patterns while also adding new ones that are unique to Pony.
Problem The Pony type system is very demanding when it comes to handling errors. The lack of null means that you are forced to initialize every variable and explictly handle every possible source of initialization error. In return, you get freedom from Null Pointer Exceptions and their equivalents. However, a naive use of Pony’s None type when initializing dependencies can lead to poor programmer ergononmics and frustration. This is particularly true when constructing actors.