Trong cuộc sống thực, rõ ràng, chúng tôi sẽ làm một cái gì đó phức tạp hơn hơn là chỉ nhắc lại một chuỗi. Nhưng điều gì sẽ xảy ra nếu chúng ta muốn để xử lý chỉ có một phân nhóm ngoại lệ của chúng tôi ở đây, và xử lý các loại khác ở một nơi khác? | and striking simplification of the physics involved. Instead of being opposites he sees turning the light off and on as variations of the same process. There s a bright and a dark light and you can turn either one on. In object-oriented lingo both the bright light class and the dark light class have a turnOn operation or method. Like the dress method of the Boy and Girl classes in chapter 4 this is polymorphism a case of different actions being represented as basically the same. In this section we ll see how Null Objects work and then discover how to use them with the Strategy pattern. Mixing dark and bright lights A Null Object is the dark light of our object-oriented world. It looks like an ordinary object but doesn t do anything real. Its only task is to look like an ordinary object so you don t have to write an if statement to distinguish between an object and a nonobject. Consider the following user UserFinder findWithName Zaphod Beeblebrox user- disable If the UserFinder returns a non-object such as NULL or FALSE PHP will scold us Fatal error Call to a member function disable on a non-object in on line 2 To avoid this we need to add a conditional statement user UserFinder findWithName Zaphod Beeblebrox if is_object user user- disable But if user is a Null Object that has disable method there is no need for a conditional test. So if the UserFinder returns a Null Object instead of a non-object the error won t happen. A simple NullUser class could be implemented like this class NullUser implements User public function disable public function isNull return TRUE The class is oversimplified since it implements only one method that might be of real use in the corresponding user object disable . The idea is that the real user class or classes would also implement the interface called User. So in practice there would be many more methods. Null Strategy objects A slightly more advanced example might be a Null Strategy object. You have one object .