Open Closed Principle and legacy code

As discussed previously, the Open Closed Principle states that code should be open for extension yet closed for modification. This principle is designed to prevent the issues with legacy code.

If the modification that has been requested of you is one that will change the behavior of a specific piece of the application, then try to instead clone the method in question and modify the clone. Then the part of the application that needs the change can call the clone instead. This will prevent the change from affecting any parts of the application except the parts you are intending to affect.

Until we know for sure that the code we just avoided is not being used elsewhere in the application, we can't delete it. Eventually, once we are sure that the old code is truly orphaned and not used, we want to clean up and delete the unused method to maintain a code base with just a little less cruft.

On the other hand, if the change is for a bug, then the fix is a little more complicated. You must first determine whether the bug should be fixed everywhere that this code might be used, or whether the bug is relative only to a specific portion of the application. When in doubt, fall back to cloning the method and only affecting intentional parts of the application.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.224.51.77