lundi 22 février 2016

Encapsulating builders in Java

I have 2 builders in my codebase, which can be accessed like this :

return new Developer.Builder("John", "Doe").age(30).build();
return new Manager.Builder("Eve", "Page").age(40).build();

I want to make the API simpler by encapsulating in an enum :

return Google.Developer.DevBuilder("John", "Doe").age(30).build();
return Google.Manager.ManagerBuilder("Eve", "Page").age(40).build();

My goal is to simplify the process for

  1. Changing company names from Google to Microsoft
  2. If a new role is added (apart from Developer and Manager), users of my code can know about it in one place.

Only option which comes to my mind is having company name as enum - but then I won't be able to implement builder pattern.

Aucun commentaire:

Enregistrer un commentaire