1

I would like to hear what all relationships exists here. I assume that here exists relationships like dependency and aggregation with 1-1 multiplicity?

public class Main {

    public Main() {
        Model model = new Model();
        View view = new View();
        Controller controller = new Controller(view, model);
    }

    public static void main(String[] args) {
        new Main();
    }

}

public class Controller {

    private Model model;
    private View view;

    public Controller(Model model, View view) {
       this.model = model;
       this.view = view;
    }

}

public class Model { ... }

public class View { ... }
1

1 Answer 1

1

It's simple, there is no need here for reverse engineering (constructing the model from code).

Main has three associations: one with Model, one with View and one with Controller, while Controller has two associations: one with Model and one with View.

Notice that there is no need for the associations Main-Model and Main-View because they can be derived via main.controller.model and main.controller.view.

The association Main-Controller (as well as Main-Model and Main-View) can be viewed/modeled as a composition, since a main program instance (a process) is composed of a controller instance, which is bundled with a model and a view instance. All three compositions come with a lifecylce dependency: any model, view and controller instance existentially depends on its main aggregate instance.

Sign up to request clarification or add additional context in comments.

2 Comments

I'd call Main's relationship with Model, Controller, and View a dependency at most, since they are only created in its constructor, and not fields of the class. Odd choice, but still. And you could spend quite some time discussing if controller model and controller view are aggregations or associations. But it'd be time best spent differently so I like how you gloss over that. :)
You are right, it's not really clear what the intended meaning of this piece of code is. Declaring local variables in the constructor for having references to the model, view and controller doesn't make sense (see, e.g., stackoverflow.com/questions/20138948/variables-in-constructor). That's why I interpreted this (without much thought) as intending to have normal references via normal reference properties declared as class members.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.