Question

My main problem is to implement communication with database server which contain info about Employees, Tasks, Projects and Departaments entities. I don't know what entities will be contained in DB in advance (i.e it is possible to add new type of entity (e.g. company) to a DB). Let we're implementing MVC such that we've created the following 3 abstract JAVA classes:

public abstract class Model{
    public abstract Data getData();
    public abstract void setData();
}
public abstract class Controller{
    private Model model;
    private View view;

    public abstract void set_view(View view, Data data);
}
public abstarct class View{
    public abstract void generate_view();
}

Is it make a sense that we wraped this classes in an abstract factory like this:

public abstract class MVCFactory{
    public abstract Model createModel();
    public abstract View createView();
    public abstract Controller createConteroller();
}
public abstract class ControllerCreator{
    public abstract Controller createController();
}
public abstract class ModelCreator{
    public abstract Model createModel();
}
public abstract class ViewCreator{
    public abstract View createView();
}
Was it helpful?

Solution

To get a clear answer you have to rephrase your question, explaining what problem are you trying to solve.

If what you want is to create MVC model instances, keeping the details of the creation in one coding module, then yes this is absolutely meaningful. Actually, even then I would create a container interface MVCModel which would have tree properties, a Model, a Controller and a View. The MVCFactory would have one create function which would instantiate an MVCModel object.

public interface MVCModel{
    Model getModel();
    View getView();
    Controller getController();
}

public abstract class MVCFactory{
    public abstract MVCModel createModel();
}

Hope I helped!

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top