Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to express the relationship between Factory or Helper class and the objects it can generate with UML class diagram

Utility/Helper and factory classes are still frequently used in core Java. For instance, java.util.Collections, java.nio.file.Files are utility classes, java.nio.files.FileSystems and java.nio.files.Paths are factory classes with static factory methods.

My question is how to make use of UML class diagram to express the relationship between these factory or utility/helper classes and those objects they can generate?

like image 848
Rui Avatar asked Dec 08 '25 18:12

Rui


2 Answers

If a class uses another class they connect with a dashed line arrow. By saying uses it means that class A has declared class B inside a method, as parameter or calls it statically.

class A {
    public void test(B b) {

    }
}

or

class A {
    public void test() {
         B b = ...
    }
}

or

class A {
    public void test() {
        B.teststaticmethod();
    }
}

If a class depends on another class they connect with a line arrow. By saying depends it means that class A has class B as private member inside.

class A {
    private B b;
}

With this knowledge you can model it yourself.

like image 89
ddarellis Avatar answered Dec 10 '25 11:12

ddarellis


There are lots of examples for the factory pattern, like in uml-diagrams.org

Helper classes would just use dependencies to the multiplicity of classes they reference.

enter image description here

like image 30
qwerty_so Avatar answered Dec 10 '25 10:12

qwerty_so



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!