I'm working on a java project where I take in some JSON objects and have to then go through them to create a domain object that I need to then further process. Currently the constructor of this object is doing a lot of work to create an instance, it looks something like this:
public class DomainObject {
private Strging field1;
private List<DifferentObject> objectList;
public DomainObject(ObjectFromJson obj1, ObjectFromJsonV2 obj2) {
//do a bunch of parsing to create the new objects for the list and create generate data for the fields
}
}
This doesn't seem like good practice. It's not easy to test and do logging. The problem is I don't really know where it's best to do this. A static method belonging to this class? A builder or factory doesn't seem appropriate here either, since I only need to create this one type of object. I was leaning on just doing the object creation in the method that initially invokes the DomainObject constructor, but since there are two places in my code where this happens. it would be a case of repeating the same object creation code.