jeudi 1 octobre 2020

Code reuse when the business logic is heavy

I have two different client classes which want to heavily reuse certain piece of code,

Example,

class Client1{
    ReuseClass1 class1;
    ReuseClass2 class2;
} 

class Client2{
    ReuseClass1 class1;
    ReuseClass2 class2;
} 


class ReuseClass1{
    method1(int a, Obj b) 
    method2(Obj a, List<x> xList>
    method3(Obj a, Obj B, Obj c) 
} 

class ReuseClass2{
    method1(Obj a) 
    method2(List<Obj> c, Map<int, int>) 
} 

As you can see, client 1 and client 2 requires the use of above Reuse classes. Since the business logic implementation was heavy, I have extracted out in a separate classes for reuse, ReuseClass1 and 2.

Unfortunately, they aren't static because those are business logic and I cannot keep them as static methods and subsequently as Utility class.

Unfortunately, above two classes cannot have a definite super class because there is no definite interface methods. They are just 'whatever-reuse-methods-related-to-this-class', put it inside.

Having the raw classes just for reuse purpose makes the codebase looks ugly though. But I didn't have any other choice.

Is there any better way to write clean code?

Aucun commentaire:

Enregistrer un commentaire