简体   繁体   English

如何在类图中表示 Python 中的静态方法?

[英]How can I represent the static method in Python in a class diagram?

The static methods in the Python are logically linked to the class and exist within it, but they are not a member method or a class method. Python 中的静态方法在逻辑上与类相关联并存在于其中,但它们不是成员方法或类方法。 How can I represent it in a class diagram , How to distinguish it from the rest of the methods?我如何在类图中表示它,如何将它与其他方法区分开来?

// Suppose this is the method
@staticmethod
def is_work(day):
   if day.weekday() == 4 or day.weekday() == 5:
       return False
   return True

Both @classmethod and @staticmethod map to the UML static property, which means that they should be rendered with an underline on a diagram. @classmethod 和 @staticmethod 都映射到 UML 静态属性,这意味着它们应该在图表上用下划线呈现。

However, there is nothing built in to UML to allow you to distinguish between them.但是,UML 没有内置任何内容来允许您区分它们。 If you use a standard name for the cls parameter then that will at least allow some visual distinction.如果您为 cls 参数使用标准名称,那么至少可以在视觉上进行区分。 If you want to go a little further I would suggest defining a stereotype to ensure it is obvious.如果你想更进一步,我建议定义一个刻板印象以确保它是显而易见的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM