mardi 9 août 2016

Is it a good design to call private methods inside a constructor?

Say I have the following class:

public class FormContainer {

    private ExternalDao externalDao;

    private final OrderForm orderForm;

    private final List<OrderFormContent> formContents;

    private final List<OrderAttribute> formAttributes;

    private final List<OrderFormSection> formSections;

    private final HashMap<String, List<OrderAttribute>> formSectionsAttrMap;


    public FormContainer(OrderForm orderForm) {

        this.orderForm = orderForm
        initializeOrderForm();

    }

    private void initializeOrderForm() {

        formContents = externalDao.getFormContents(orderForm);
        //same for the other properties

    }


    //getters & setters

}

I am using this class to be able to hold all the fields that I will need to refer through the application. I am still learning good design and bad design practices so I am wondering if this bad design to initialize the properties of orderForm.

If so, how could it be improved? thanks

Aucun commentaire:

Enregistrer un commentaire