lundi 27 avril 2015

Scala - Does pattern matching break the Open-Closed principle?

First of all, I know this question has been asked previously here, but it wasn't clear for me.

Pattern matching is used to make a function react to different types of data. One would say that if my Pattern Matching case has 4 cases and one month later I need to add a 5th one, I'll be breaking the Open-Closed Principle. I agree to that.

In a worst case scenario: Let's suppose I'm using a closed library (I can't touch code inside it) and I need to extend its functionality. The functionality I want to extend is indeed a Pattern Matching function. What should I do?

I think pattern matching is OK if I'm totally sure my Object doesn't change very often and will never require to be extended by others.

What's your opinion about using this technique? This is more like a debate than a question.

Thanks,

Aucun commentaire:

Enregistrer un commentaire