Skip to content Skip to sidebar Skip to footer

How To Represent The Relationship Between An Instance Of A Class And The Class That Gets It As An Input?

I have a class called House. The instance of this class is house. class House: def __init__(self, height, length): self.height = height self.length = length

Solution 1:

I have another class called Person. This class gets several inputs including an instance of House

the instance of House is not only given in argument of the constructor of Person but it is a property of the class (self.house = house), so :

enter image description here

I said name is a String which is very probable.

All attributes / property / operations are public to respect Python rules.

At the level of a class diagram it is not possible to see from where the arguments of the operation come from, for that you can use an interaction (e.g. a sequence diagram like in your next question where I also put an answer) or an activity

(Out of that it is strange your house has a length but not a width, so it is mandatory a square)

Solution 2:

Still, there are many ways to present what you have. Anyhow, here's a viable way.

Basically you should show just the static classes in a class diagram. That shows how they are related. Since there are only House and Person it should not be difficult to sketch them on a single diagram. When things get more complex you might need more diagrams to show sub-domains.

Now the "input" part of the question: Here it's just best to create a sequence diagram to show how instances are created and passed around in parameters of messages. In order to show different scenarios you would create an extra SD per scenario. You should not overdo it with details. That is: avoid graphical programming! Just show enough to get a good overview.

It would be possible to show instances and classes semi-statically on a single object/class diagram. But that rarely makes sense. So you should just go with a SD as stated above.

Post a Comment for "How To Represent The Relationship Between An Instance Of A Class And The Class That Gets It As An Input?"