I have a class which is called TestPlan (to put it simple, let’s assume that it’s a usual java bean).
I need to store TestPlan instances in xml-files (1 instance per file). The most appropriate way to do it which I can see is using another class which should do only xml-related work.
It’ll have methods like:
public TestPlan parseTestPlanXml(InputStream xmlFile) {
TestPlan testPlan = new TestPlan();
//parse xmlFile and set testPlan fields via setters
return testPlan;
}
public OutputStream writeTestPlanXml(TestPlan testPlan) {
//the actual implementation just copies the original xmlFile,
//makes necessary modifications
//and writes it to ByteArrayOutputStream
...
}
Which name would you suggest for this class? (btw, if you can also suggest better names for these 2 methods then don’t hesitate to do that).
Thanks!
If the class is only responsible for loading/saving
TestPlanobjects, and it has no other similar methods to load/save objects of other classes, it could beThis way, in accordance with the DRY principle,
TestPlanandXMLare not repeated unnecessarily in the method names.However, if the class is dealing with multiple types, the
loadmethods need to have distinct names since a method can’t be overloaded on the return type only.savewould be fine to overload with different type parameters, but for consistency the same naming convention should be used for both.