假设我们有Book一个包含year_published公共字段的类。如果我想实现 NullObject 设计模式,我需要定义NullBook行为相同Book但不做任何事情的类。
NullBook问题是,分配字段时的行为应该是什么?
Book book = find_book(id_value); //this method returns a NullBook instance because it cannot find the book
book.year_published = 2016; //What should we do here?!