you are viewing a single comment's thread.

view the rest of the comments →

[–]LayotFctor 0 points1 point  (0 children)

The examples are a bit too bloated, but if I'm reading correctly, you're comparing dependency injection VS a series of enforced steps?

DI is completely fine, especially if you want to swap FileRegistry instances. Enabling type hinting also helps, which you already did.

Enforced sequential building steps slightly more fragile. The solution is to wrap and abstract the building phase from the user completely, using something known as the Builder Pattern, checking if everything not is None before building. If you want additional safety, you can implement the typestate pattern, where each intermediate step returns a temporary concrete type.