When null object Patterns first discovered this pattern, it was because Uncle Bob's classic book Agile Principles, Patterns, and Practices In C #! The following is an example from the book: [java] Employee e = DB. GetEmployee ("Bob"); if (e! = Null & e. IsTimeToPay (today) e. Pay (); through this small example, we will find that we have to judge e in the condition every time! = Null. 1. The code is repeated. 2. The code is ugly. 3. Easy to write. Solution: [java] Employee e = DB. getEmployee ("Bob"); if (e. isTimeToPay (today) e. pay (); [java] public abstract class Employee {public abstract bool IsTimeToPay (DateTime time); public abstract void Pay (); public static readonly Employee NULL = new NullEmployee (); private class NullEmployee: Employee {public override bool IsTimeToPay (DateTime time) {return false;} public override void Pay (){}}} The following is a more practical example: [java] // present game item or (int I = 0; I <world. getRow (); I ++) {for (int j = 0; j <world. getCol (); j ++) {game. getGraphics (). drawPixmap (world. getItem (I, j), j * world. getItemSize (), I * world. getItemSize ();} This part of code is mainly used to draw training and viewing elements. World. getRow gets the number of rows in the Connected View Matrix world. getCol gets the number of columns in the serialization Matrix world. getItem is used to obtain the Image at the specified position of the link. getItem code: [java] public Pixmap getItem (int I, int j) {switch (datas [I] [j]) {case 1: return Assets. a; case 2: return Assets. b; case 3: return Assets. c; case 4: return Assets. d; case 5: return Assets. e; case 6: return Assets. f; case 7: return Assets. g; case 8: return Assets. h; case 9: return Assets. i; case 10: return Assets. J;} return Assets. NULL;} resource Loading Code: [java] Assets. a = g. newPixmap ("a.png", PixmapFormat. ARGB8888); Assets. B = g. newPixmap ("B .png", PixmapFormat. ARGB8888); Assets. c = g. newPixmap ("c.png", PixmapFormat. ARGB8888); Assets. d = g. newPixmap ("d.png", PixmapFormat. ARGB8888); Assets. e = g. newPixmap ("e.png", PixmapFormat. ARGB8888); Assets. f = g. newPixmap ("f.png", PixmapFormat. ARGB8888); Assets. g = g. newPixmap ("G.png", PixmapFormat. ARGB8888); Assets. h = g. newPixmap ("h.png", PixmapFormat. ARGB8888); Assets. I = g. newPixmap ("I .png", PixmapFormat. ARGB8888); Assets. j = g. newPixmap ("j.png", PixmapFormat. ARGB8888); Assets. NULL = new AndroidPixmap (Bitmap. createBitmap (40, 40, Config. ARGB_8888), PixmapFormat. ARGB8888); by using the null object mode, you do not have to consider whether the picture of the connected element obtained is null during painting, making the code clearer and more elegant, on the other hand, rendering does not have to know whether the elements I want to draw are legal or not, which is in line with the OO encapsulation idea. Here we use a transparent concatenation element as "null object ".