Say, I have a code file where all the core logic is located. In addition, I have some custom logic that is defined by some flags, like

if (a && b && c) {}
if (!e && f) {}
else if(d && c) {}

These custom logic pieces are spread over the core logic file. In general, it runs default logic, but sometimes custom.

I find it messy to have to look through the core file and figure out where the default logic is applied, and where there is custom code.

How could I refactor the code so that to have some kind of rules file which would declaratively define custom logic cases and could be imported in the main logic file?

I am not asking for a detailed solution, but more for a concept or pattern on how I could solve this issue. Thanks!


I think what you are looking for is a Business Rules Engine. It provides a nice neat reusable way of decoupling your "custom logic" from the "core logic". There are a number of lightweight FOSS BREs out there, hopefully in a language you're comfortable with, as well as some exceedingly expensive ones that are sold to organisations who want to be able to fire all of their developers and use Business Analysts to write all of their applications. I've not seen that end well ;)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.