简体   繁体   中英

How do I represent an abstract class usage?

I have Class A calling an abstract class B and class B returns an object. How can I represent this in UML? Also, is there a resource that shows source code and then the equivalent UML diagrams? This would help me a lot! I have a hard time understanding the definitions of association, aggregation, etc... without actual code as an example.

For example,

Class A {
    constructor {
        B = B.hello();
    }
}

Abstract Class B {
    public static hello() {
        return new C();
    }
}

Class C extends B {

}

You can show this using two diagrams:

  1. class diagram: A is related to B , and C extends B . Nothing else.
  2. sequence diagram: shows the flow of the calls: someone calls A.constructor , then from A.constructor show a call to B.hello , which then creates a new C .

The specific UML syntax for these diagrams can be found here .

Regarding code and UML, it is problematic since:

  1. Not all UML elements can be modeled in code (many to many relations have no exact code translation)
  2. For UML elements that can be translated directly to code, there are many different implementations, all of them correct.

I don't know of a site that does this, but it could be an interesting project...

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