vendredi 7 février 2020

Standardize the construction of the object Design Pattern

I have two java classes

Job

    public String id;
    public String name;
    public String status;

Workflow

    public String id;
    public String name;
    public String Status;
    public Date nextDate();
    public String type;

I would like to build a method that builds a Workflow type object with Job characteristics

public Workflow buildWorkflow(Job job){

Workflow test = new Workflow();

test.setId(job.getId());
test.setName(job.getName())
test.setStatus(job.getStatus());

test.setNetDate(new Date());
test.setType("java");

return test;
}

how can i standardize the construction of the object if the object changes?

JobStandard

    public String id;
    public String name;
    public String status;

I should completely rewrite the method:

public Workflow buildWorkflow(JobStandard jobstandard){

Workflow test = new Workflow();

test.setId(jobstandard.getId());
test.setName(jobstandard.getName())
test.setStatus(jobstandard.getStatus());

test.setNetDate(new Date());
test.setType("java");

return test;
}

Tips ?

Aucun commentaire:

Enregistrer un commentaire