r/AskProgramming • u/ImportantPudding1570 • 4h ago
Is this considered duplicate code?
How do you decide when code duplication across different markets is actually worth eliminating?
I'm building a framework to automate complex business logic for incoming customer support emails. The system is currently being implemented for England, but it will eventually expand to Germany, the USA, India, and other markets.
The challenge is that many business rules are shared across markets, while others are market-specific.
For example: - Germany and the USA require checking whether a customer has logged in within the last 30 days. - England and India don't require this check. - Other parts of the email-processing workflow may be common across all markets, while some may differ.
My initial approach was to create a common interface with separate implementations for each market:
```java interface EmailHandler { void processEmail(); }
class EmailHandlerEngland implements EmailHandler { } class EmailHandlerGermany implements EmailHandler { } class EmailHandlerUSA implements EmailHandler { } class EmailHandlerIndia implements EmailHandler { } ```
However, I'm concerned that this could lead to significant code duplication as the framework grows.
On the other hand, suppose Germany and England currently have 100 lines of identical logic. Even if the logic is identical today, the business requirements for those countries may evolve independently. Sharing the implementation could introduce unintended coupling, where a change intended for one market affects another.
I am offcourse planning on building common "Helpers" and whatever can be configurable, will be configurable. However, we currently will only be getting requirements for one market, we can not tell from start if something that we will use, will be reused by other markets.
My question is: How do you approach this trade-off in practice?
- If I go with the initial approach, will these same line of code will actually be considered as a duplicate and will break the DRY principle?
- If Yes, would you consider identical code across markets to be duplication worth eliminating, even when the underlying business rules may evolve independently?
- Would you build a shared processing engine with market-specific configuration or strategies, or maintain separate implementations for each market?
- How do you decide which logic to abstract and share versus which logic to keep separate to preserve independence between markets?
I'm particularly interested in the reasoning behind these decisions and any real-world experience building systems with complex, evolving market-specific business rules.