Code: domain-driven design, immutability, Ruby, testing, validity
Comments Off on Builder Methods
In fact, over time Iâ€™ve developed a guideline for myself that external callers canâ€™t actually use the base constructor for an object. Put another way: the outside world canâ€™t use
newto instantiate an object with an expectation of a specific state. Instead, there must be an explicitly named builder method on the class to create an object in a specific, valid state.
This was a brief aside at the tail of a longer discussion of interdependent and redundant tests. It really caught my attention and I’d like to hear it more thoroughly investigated. In the hopes of attracting Corey’s attention, I offer this cat pic and an exploration of the benefits of a similar practice I have: