-3

I was reading a text about SOLID principles and Open/Close principle and it said that : "The main idea of this principle is to keep existing code from breaking when you implement new features"

what it means by breaking code?

  • 2
    "keep existing code from breaking" in that case means that existing code should work just like it did before. The added new changes should not suddenly result in existing code giving wrong results or no longer working in any other way. – OH GOD SPIDERS May 31 '22 at 12:54
  • 1
    I’m voting to close this question because it belongs to https://softwareengineering.stackexchange.com/ - probably. – tevemadar May 31 '22 at 13:12
  • Note: by tagging a question like this with `java`, you expose it to a lot of people who know about the tags they follow, but don't know the answer. Some of them will downvote it or close-vote it as a result. – Matt Timmermans May 31 '22 at 16:52
  • "breaking" in this context means "introducing bugs." As in "The main idea of this principle is to prevent the introduction of bugs in existing code when you implement new features." – Steven May 31 '22 at 17:54

1 Answers1

1

You "break" existing code when you modify it in a way that prevents it from working for existing or intended use cases, when it worked fine for those use cases before you modified it.

By writing your code so that it is open for extension, but closed for modification, you allow the code to be used in new situations without having to modify it. No modification = no breaking.

Matt Timmermans
  • 53,709
  • 3
  • 46
  • 87