简体   繁体   中英

How to represent two different types of data being returned by a class method in a UML diagram?

I have the following method:

    def getInvoiceById(self, id):

        for invoice in self.invoices:
            if invoice.id == id:
                return invoice

        return False

inside a class called User . How do I represent the return type (after the Parenthese) in the UML class diagram? since it can either be a Boolean or another class invoice .

Besides the fact that this is a really bad implementation (you rather should return None than False ) you would have the return type of what ever ìnvoice would be (probably Invoice ). So assuming that it would just be

+getInvoiceById(id):Invoice

(I intentionally omit self since it is a mandatory parameter in Python.)

The exception can be noted as a constraint like { returns False if no id found } .

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