DEV Community

loading...

Discussion on: Practical Coding Patterns For Boss Developers #1: Special Case

Collapse
shoupn profile image
Nick Shoup

Thank for sharing this James. I've seen this and used this pattern before, but didn't really have a name for it. Thanks for the clarification. I've always thought about it as a part of implementing the factory pattern.

Collapse
jamesmh profile image
James Hickey Author

You're welcome 🤜🤛

I agree, there just seems to be a natural connection between this pattern and the factory pattern since you need something to decide how to instantiate the classes.

Usually, the pattern is for avoiding null issues, but I really like the idea of being intentional about splitting classes up more semantically instead of having internal variables that hint that the object is in a very specific or special state.

I've used the pattern when building viewModels too, for example. Each variant can each format themselves totally differently 👍