vendredi 10 février 2023

java composition to reduce code complexity

Let us say there is a class LargeClass with 4k lines of code. I would like to reduce the file size to manage it better by extracting the code into some other classes.

class LargeClass extends SomeLibraryClass {

  void featureOneLargeMethod1() {
  }

  void featureOneLargeMethod2() {
  }

  void featureOneLargeMethod3() {
  }

  void featureTwoLargeMethod1() {
  }

  void featureTwoLargeMethod2() {
  }

  void featureTwoLargeMethod3() {
  }

}

I could create two classes FeatureOne and FeatureTwo and move the corresponding methods into these new classes but the featureOneLargeMethod1() calls protected SomeLibraryClass.someLibraryMethod() which makes it impossible to move these methods. I was thinking of creating a wrapper interface that LargeClass implements and thereby FeatureOne and FeatureTwo class can access them. Any better approach in java or kotlin instead of creating the wrapper interface?

Aucun commentaire:

Enregistrer un commentaire