Currently we have a structure like the following in our UML Class Diagram:
Node --1------------*-- Data
^ ^
| |
SpecialNode--1----*--SpecialData
Eg SpecialNode is a specialization of the class Node and SpecialData is a specialization of the class Data.
The idea is that each SpecialNode only has SpecialData, and no 'normal' Data. However, some would argue that since a SpecialNode is a Node, it can have relationships to both Data and SpecialData.
Is there any reference material available that would clarify if SpecialNode can have only SpecialData? If not, how could we inforce this (in a clean way).
Kind Regards, Joos
Indeed, such modeling implies that SpecialNode
inherits all the properties of Node
, including Data
. Otherwise it would contradict the Liskov Substitution Principle which is an important rule for good design. I would suggest not to define your Node
and SpecialNode
as "having" Data
or SpecialData
but rather have an interface to Data
. For Node
it will be associated with Data
object and for SpecialNode
it will be associated with SpecialData
object.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.