DEV Community


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

dbanty profile image
Dylan Anthony

This feels a lot like the state pattern to me. How is it different?

jamesmh profile image
James Hickey Author

Seems very similar, except the special case is usually used for replacing null values as a starting point.

When used to expose polymophic behaviors, the state pattern uses a "container" class to hold the state using composition, but the special case classes use sub-typing (thus the need for a factory of some kind).