0

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,

Community
  • 1
  • 1
  • Well... First of all... your example will have the same limitation for almost anything. Be it pattern-matching or if-else or anything else in the programming. – sarveshseri Apr 27 '15 at 13:10
  • @SarveshKumarSingh I know, but using an If/Else or a Switch is not the best approach. I would use good OO principles to solve that. My point is that in some cases using Pattern Matching is as bad as using nested if statements. – Santiago Ignacio Poli Apr 27 '15 at 13:23
  • 2
    "This is more like a debate than a question." Good debate, but I don't think this is a place. – vptheron Apr 27 '15 at 13:29
  • I believe this question has been adequately answered before thus the vote to close. If that other answer is not clear, try posting comments there to see if some of the contributors might be able to provide additional clarity. – cmbaxter Apr 27 '15 at 13:42

0 Answers0