java - remove duplication -
I have a class that includes 10 ways which are doing almost the same thing except an important event, two examples are given below. Gone:
public string ATP operation (string pin, string amount) {doSomething (); DoMoreStuff (); Requestbuilder.buildATypeRequest (PIN, zodiac); DoAfterStuff (); }
public string BTypeOperation (string name, string sex, string era) {doSomething (); DoMoreStuff (); Requestbuilder.buildBTypeRequest (name, gender, age); DoAfterStuff (); }
As you can see from the methods given above, they are similar to calling different methods provided by requestBuilder. The rest 8 are also similar. There is a lot of duplicate code here, I think it's a better way of implementing it, but do not know how. Any ideas and suggestions are appreciated
Thanks, Sarah
Use something that accepts all these types of criteria:
public requestbuilder {// Setsers and Gates Public Requests Build for All Properties () {doStuff (); Request request = new request (this); DoAfterStuff (); Return request; }}
and then
New RequestBuilder (). SetAge (age) .setName (name) .build ();
Comments
Post a Comment