So... when there're features development going on, we developed the feature and published it. But at some point, new features arrive and it may so happen that we can't support it with the existing desing so we introduce design patterns i.e. factory, strategy, etc and incorporate those changes.
Say, for example, a factory pattern is introduced and currently there're two different types of classes A and B.
And the factory method is responsible to generate an instance of A or B based on some logic.
And later, say for new requirements, there's a new class C. And A, B, C has 4 functions to do. A, B, C has been implemented based on an interface abstracting the core logic.
Now two functions of C is similar to B but two functions of C is different than B. Now as interface has been used here, then we have duplicate code in our codebase.
The two functions of B and C who does the same thing is duplicated in the codebase.
In such scenarios, what are the best practices to -
- Implement these in such a way so that diplicay does not arise in the first place?
- If no 1 is not possible then how to remove duplicate code from the codebase?
Top comments (0)