Consider this class diagram:
+--------+ * +------------------+ * afraid-of +------------+
| Garden |------>| Animal |<------------------------| Baby |
+--------+ +------------------+ +------------+
^
|
+----------+------+
| |
+------+------+ +------+-----+
| Cat | | Wolf |
+-------------+ +------------+
动物有两个作用:
- They will be walking around the garden (Class Instance)
- The baby is afraid of some animals (Class Type)
What baby should keep? One instance of each animal it s afraid of? (sounds like poor design) The type name? (I always try to avoid refactoring)
如何解决这一问题? (如果使用C#,我只提到它,因为我希望这里有一种普遍、无语言设计模式或想法)
成就