set() def add(self, child: PathComponent): self.children.add(child) def remove(self, child: PathComponent): if child in self.children: self.children.remove(child) def set_checked(self, checked): for c in self.children: c.checked = checked def get_checked(self): child_status = [] for c in self.children: # Compositeはオペレーションを子供に委託する child_status.append(c.get_checked()) if all(child_status): return Checked.Checked elif all([s == False for s in child_status]): return Checked.Unchecked else: return Checked.Intermediate イメージ