Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What's the UML representation for a class that creates and returns another class without containing it?

Tags:

php

mysql

uml

I'm not sure how to represent this scenario in a UML class diagram.

An example of what I mean:

A typical Mysql class which handles the DB connection, but delegates the statement construction and execution to another class called MysqlStatement, so that the Mysql class has one method called Mysql::prepare() which returns the Mysqlstatement class (not containing it), like so:

    class Mysql extends DB_Connection {

    public function connect($user, $pass, $dbhost, $dbname)
    {
        $this->dbh = mysql_connect($dbhost, $user, $pass);
        // ...
    }

    /**
     * Connects to the DB, then creates and returns the statement object
     * @param string $query
     * @return MysqlStatement
     */
    public function prepare($query)
    {
        if (! $this->dbh) $this->connect();
        return new MysqlStatement($this->dbh, $query);
    }

}

Note that, as far as I know, there's no composition/aggregation/association, because no class contains the other. So I'm not sure how to represent this relationship. I need to do it to put everything in order and get a glimpse of the system.

like image 395
Luis Martin Avatar asked Oct 15 '25 09:10

Luis Martin


1 Answers

You can represent the relationship in UML using a uni-directional usage (instantiation) relationship.

Depending on your tooling, the graphics may be drawn a little differently, but here's a really simple example showing what you want.

enter image description here

See this reference for a description of this type of relationship.

For reference, here's what a sequence diagram might show (details limited obviously)

enter image description here

like image 124
Ryan J Avatar answered Oct 16 '25 21:10

Ryan J



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!