What if the parent can’t exist without a child? (Class diagram)

I’ve built a matchmaking system where two of the classes look like this:

enter image description here

I know that it actually looks like an inheritance, but in the code it doesn’t extend to the PlayerInMatchmaking and the program is completed and already tested (so I prefer to not change anything). Can I write it as inheritance? If not, then what can I write it? In the picture, I wrote it as aggregation, but aggregation can stand without the related class, while it actually can’t. But if I write it as composition, they are actually not a parent-child relation. Is this kind of design wrong? Any suggestion? Thank you

1

Inheritance is not a goal in life, and there is no reason to introduce it if there is no need. In fact, it is quite the contrary: the usual recommendation is to prefer (object) composition over inheritance.

As you used aggregation (more precisely a “shared aggregation”), be aware that modern UML does not define any semantic for aggregation. The white diamond does therefore not add any meaning to a simple association. So better get rid of it.

If you want to say that the “Parent” requires the “Child” to exist, i.e. that PlayerCandidate requires PlayerinMatchmaking to exist, you should use multiplicity of 1 on the side of PlayerinMatchmaking, meaning that each PlayerCandidate instance must be linked to exactly 1 PayerinMatchmaking instance. (if it’s the contrary, just put the 1 on the opposite side; that’s the ambiguity with Parent/child terminology). (Note: In the following diagram I also showed the property player with a role on the association end, both notations are equivalent)

class diagram corresponding to explanation above

If you’d like to say that one of the object owns the other, i.e. that the owned object shall be destroyed if the owner is destroyed, you could use UML composition (more precisely, “composite aggregation”). But if you want that the child requires the parent, then you’d need to add a multiplicity of 1 next to the black diamond.

Class diagrams depict the structure of your application, not the rules governing its operation. Some rules can be expressed in the structure of your program, but many cannot. I don’t see anything wrong with your diagram. It clearly depicts that a PlayerCandidate holds a reference to a PlayerInMatchmaking.

Class diagrams are not the place to describe many of the constraints your application needs to adhere to. Other forms of documentation are better equiped to handle this. Requirements documents and unit tests (which should be written based on the requirements) are the first things that come to mind.

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật