Design Patterns · Senior · Question 15 of 75

What is the expression problem, and how does it show up in TS?

Explanation

With a discriminated union, adding a new handler function is easy, but a new variant requires editing every switch. In OOP with classes, adding a new type is easy, but a new operation is expensive (solved with Visitor). The choice depends on what will change more often.

Further reading

Problem with a question

Design Patterns · Senior · question 15

Test yourself

Take the Design Patterns · Senior quiz: questions and options are shuffled, and you get a review of your mistakes at the end.

Take this quiz