I have a class which updates an object. The class takes a String id
in its constructor and returns the appropriate class based on the id
. I think these two methods should be separated into their own classes as returning an object based on a String id
will probably have uses elsewhere in the code base.
I've considered adding the functionality which returns the object to update into its own static method:
ObjectToUpdate = Utils.getObjectToUpdate(id)
Is there a better way or a design pattern?
UpdateContestantObj c = new UpdateContestantObj(childWithParentRatingsObject.getCoupleId());
c.getContestantObj().setSortVal(singleScoringFM.getScore());
c.persistContestant();
public class UpdateContestantObj {
private String id;
private ContestantObj contestantToSave = null;
public ContestantObj getContestantObj(){
return this.contestantToSave;
}
public UpdateContestantObj(String id){
this.id = id;
SimpleSortingVector simpleSortingVector = (SimpleSortingVector)FutureContent.future.getContent(Constants.CONTESTANTS_DATA);
Enumeration contestantsEnumeration = simpleSortingVector.elements();
while(contestantsEnumeration.hasMoreElements()){
final ContestantButtonField contestantButtonField = (ContestantButtonField)contestantsEnumeration.nextElement();
if(contestantButtonField.getContestant().getId().equalsIgnoreCase(this.id)){
contestantToSave = contestantButtonField.getContestant();
}
}
}
public void persistContestant(){
contestantsStore.setContents(contestantToSave);
contestantsStore.commit();
}
}