mardi 4 février 2020

What is the best way to split the code in builder class?

I have decided to create a builder for a very large object. It started as a pretty small class with around 200 lines of code but currently it went over 700 lines. Actually the class exposes endpoints to concrete builders and has some methods which add data which is irrelevant to the concrete builder used.

Currently I have thought of 3 ways to split the code in separate files.

Option 1) export methods in extension method classes Option 2) export methods in partial classes Option 3) add class like BaseBuilder and create ConcreteBuilder1 : BaseBuilder, ConcreteBuilder2 : BaseBuilder and to access the concrete implementation through something like factory.

Option 3 is not really preferable since the builder is already used in more than 1000 methods and it won't be easy to change how it is called in so many places.

So my question. Should I leave the builder as it is? Which option is considered as best and which as worst practice? If you faced such issue before, how have you fixed it?

Aucun commentaire:

Enregistrer un commentaire