简体   繁体   中英

UML Is it possible to use Aggregation and Composition with two classes?

I have just began learning UML, and I was wondering if a class could composite one way and aggregate the other way (if you understand what I mean). Let's make an example:

我的例子

Maingui.java:

private controller;

public Maingui() {   
  controller = new Controller(this); 
}

Controller.java

private maingui;

public Controller(Maingui gui) {
  maingui = gui;
  doSomethingWithMainGui();
}

private void doSomethingWithMainGui() {
  maingui.doSomeThing();
}

Is this the correct way to show the association?

It's correct way to show assocation, but it's example of bad style app architecture. One of principles of good style architecture is loose coupling. You can read here about it: What is the difference between loose coupling and tight coupling in the object oriented paradigm?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM