doufan3958 2015-06-26 09:25 采纳率: 0%
浏览 55
已采纳

如何在UML类图中描述一个方法接受多种类型?

I'm working on a PHP project and I'm doing its UML documentation. I need to specify that a method accept multiple data types and I can't figure out how to do it.

For instance: I want to represent a PHP class called 'A' in a UML class diagram:

<?php 

    class A{ 
        private $_data;  

        public function __construct() { 
            $this->_data = array(); 
        } 

        public function add( $key , $value){ 
            $this->_data[$key] = $value; 
        }                        
    } 

    $oA = new A(); 
    $oA->add( 1, 'John Doe' ); // key is an int and value is a string 
    $oA->add( "Fruits" , array("Apple", "Banana", "Kiwi") ); // string, array 
    $oA->add( "pi", 3.1415 ); 
    //and so on...       
?>

Note that add() function can receive keys and values of different kind of data. So, I can't specify in my UML class diagram something like “key:integer” or “value : string[]” because their data type can change depending on what kind of data is passed when the method is called.

Is there a way to depict this fact in UML notation?

Can I specify something like:

+ add( key:mixed , value:mixed)

?

Thanks in advance!

展开全部

  • 写回答

2条回答 默认 最新

  • dounue6984 2015-06-27 04:18
    关注
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)
编辑
预览

报告相同问题?

手机看
程序员都在用的中文IT技术交流社区

程序员都在用的中文IT技术交流社区

专业的中文 IT 技术社区,与千万技术人共成长

专业的中文 IT 技术社区,与千万技术人共成长

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

客服 返回
顶部