In: Computer Science
Question 3 (1 mark) : Assume that your program has classes Family, House, LivingRoom, Bedroom,Bathroom, Kitchen. What is the most appropriate relationship among the above classes. Write a UML diagram that indicates your system architecture (classes and relationships).
Hey, I have done my best to answer your question, still you face any issue, do tell me in comments, and if the solution is helpful, do upvote... Thanks :)
*****************************
In this example, We will use multiplicity and composition relationships.
Multiplicity- It is used when cardinality of one class is depicted with respect to another class. For eg- in the above example, one house may have 0 or more families. The notation 0..* depicts zero or many.
Composition- It is used to depict the formation of one class through various other classes. For eg- in this example, the house class is composed of livingRoom , bedRoom, kitchen, bathRoom and bedRoom classes.
In Composition, if the composition class is destroyed, then the sub-classes also gets destroyed. That is, the existence of contained classes (Bedroom, LivingRoom, kitchen, Bathroom) depends on container class(House).
Compostion is represented directional line connecting the two classes, with a filled diamond shape adjacent to the container class and the directional arrow to the contained class.