简体   繁体   English

回调函数/类的UML类建模

[英]UML class modeling of callback functions/classes

I'm no expert in UML, I just took a course before I graduated that spent a significant amount of time on UML modeling. 我不是UML的专家,我只是在毕业之前上了一门课程,花了很多时间进行UML建模。 I understand the basics but I was working on a project the other day and just for my own curiosity, I was wondering how you would model a callback. 我了解基本知识,但是前几天我正在做一个项目,只是出于我自己的好奇心,我想知道如何建模回调。 Here is a portion of the code I was working on 这是我正在处理的部分代码


class OnChangeHandler():

    def my_init(self, rem, loc):
        self.remotes = rem
        self.locals = loc

    def process_IN_CREATE(self, event):
        #Do some work

    def process_IN_MODIFY(self, event):
        #Do some other work

class Watch():
    def __init__(self):

        self.wm = WatchManager()
        self. notifier = AsyncNotifier(self.wm, OnChangeHandler(loc=self.locals, rem=self.remotes))

I'm using a framework obviously, so I guess my question boils down to how would you model complex relationships where you are working with black box modules and frameworks? 我显然是在使用框架,所以我想我的问题可以归结为在处理黑盒模块和框架时如何建模复杂的关系? Is it just not even worth spending time on? 甚至不值得花时间吗? But if so, aren't the majority of programs built within frameworks? 但是,如果是这样,不是大多数程序都在框架内构建的吗? I found UML class models to be really helpful when we were learning, but now I'm just confused. 当我们学习时,我发现UML类模型确实很有帮助,但是现在我很困惑。

Just for the record. 仅作记录。 One could just model the methods for callback registration and invocation in the class. 可以只为类中的回调注册和调用方法建模。 OTOH if one wants to have more of abstraction to match the framework components and stereotypes could be used, eg by extending the Interface metaclass with an Event and Callback stereotype. 如果希望拥有更多抽象来匹配框架组件和构造型,可以使用OTOH,例如,通过使用事件和回调构造型扩展Interface元类。

You can reverse a framework by reversing the .class in order to get a class diagram. 您可以通过反转.class来反转框架,以获得类图。

See an example of a framework reverse at: http://www.ejb3.org/jar_file_reverse/jar_file_reverse.html The class diagram will give a view of the structure of the application and its architecture. 在以下位置查看反向框架的示例: http : //www.ejb3.org/jar_file_reverse/jar_file_reverse.html类图将提供应用程序结构及其体系结构的视图。

The sequence diagram is also possible in order to understand what is going on when running the application. 顺序图也是可能的,以便了解运行应用程序时发生了什么。 It helps to have a better understanding of how a .java class could react with a framework .class class. 有助于更好地了解.java类如何与框架.class类反应。 See an example at: http://www.ejb3.org/jar_file_reverse/jar_file_reverse.html#3.Sequence_Diagram_reverse_engineering It is very useful if you need to add new code and reuse existing compiled code. 请参见以下示例: http : //www.ejb3.org/jar_file_reverse/jar_file_reverse.html#3.Sequence_Diagram_reverse_engineering如果您需要添加新代码并重用现有的已编译代码,这将非常有用。

Hope this helps. 希望这可以帮助。

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

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