public HIPAAKey(String loopId, String segmentId, int segmentSequenceId,
int loopSequenceCount, int providerSubmittedLineNumber){...}
The call to this constructor then might look something like this:
new HIPAAKey("2010BA", "HI", 1, 2, 3);
Even if you are familiar with the constructor and its parameters, it can become laborious trying to keep track of which attribute is represented by each value.
A better solution would be to create a builder object which is passed to the constructor as the single parameter. In this case, the builder might look like this:
public static class HIPAAKeyBuilder {
private String loopId;
private String segmentId;
private int segmentSequenceId;
private int loopSequenceCount;
private int providerSubmittedLineNumber;
public HIPAAKeyBuilder() {}
public HIPAAKeyBuilder loopId(String loopId){
this.loopId = loopId;
return this;
}
public HIPAAKeyBuilder segmentId(String segmentId){
this.segmentId = segmentId;
return this;
}
//continue until all key values have similar methods, each
//returning the current instance of the object
....
}
Now, when you need to construct a new key, you chain calls to the builder pattern like this:
new HIPAAKeyBuilder().loopId("2010BA").segmentId("HI").segmentSequenceId(1).
loopSequenceCount(2).providerSubmittedLineNumber(3);
Then, you simply pass this as the parameter to the HIPAAKey constructor. This makes both constructing these key objects and debugging them much more clear.
No comments:
Post a Comment