如何显示一个类和另一个类之间的关系,该类将类的实例的实例作为序列图的输入? [英] How to show the relationship between a class and another class that takes the instance of the class's instance as an input with a sequence diagram?

查看:58
本文介绍了如何显示一个类和另一个类之间的关系,该类将类的实例的实例作为序列图的输入?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我将使用以前的

(我将 found消息用于 buildHouse ,因为呼叫者是未知的,也不与您的问题相关)

没有Person类的房子可以存在

如果您说的是班级,肯定可以,因为 House 的定义未嵌套在 Person 中.

如果您在全球范围内谈论实例,那么没有什么可说的是只有 Person 可以实例化 House ,所以也是.

如果您在我的question and modify it.

I have a class called House. The instance of this class is house.

class House:
    def __init__(self, steel, money):
        self.steel = steel
        self.money = money

    def housePlan():
        houseHeight = self.steel/self.money
        houseEdgeLength = self.money

I have another class called Person. This class gets several inputs and creates an instance of House. House can exist without the Person class.

class Person:
    def __init__(self,name, steel, money):
        self.name = name
        self.steel = steel
        self.money = money
   
    def buildHouse():
        house = House(self.steel, self.money)

How can I show the relationship between these two classes with UML sequence diagrams?

解决方案

How can I show the relationship between these two classes with UML sequence diagrams?

The goal of a Sequence Diagram is not to show relationships between classes, a Sequence Diagram describes an Interaction by focusing on the sequence of Messages that are exchanged, along with their corresponding OccurrenceSpecifications on the Lifelines (formal/2017-12-05 § 17.8 Sequence Diagrams)

From your code buildHouse creates a new instance of House so there is an object creation Message. Because house is a local variable the instance is immediately lost and then we can consider it is immediately deleted by the garbage collector of Python, so a DestructionOccurrenceSpecification depicted by a cross in the form of an X at the bottom of a Lifeline (§ 17.4.4.2 DestructionOccurrenceSpecification).

(I used a found message for buildHouse because the caller is unknown nor relevant in your question)

House can exist without the Person class

If you speak about the class, yes for sure because House definition is not nested in Person.

If you globally speak about instances, there is nothing saying only a Person can instantiate a House so yes too.

If you refer to your previous question in my answer I do not use a composition so the deletion of an instance of Person does not imply the deletion of the associated instance of House.

But again in buildHouse the new instance of House is immediately lost because not returned nor saved in a global variable nor saved in an attribute of Person, and then will be deleted by the garbage

这篇关于如何显示一个类和另一个类之间的关系,该类将类的实例的实例作为序列图的输入?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆