design patterns - How do I create a Null Object in C# -
In refactoring of Martin Fowler, there is talk of creating a null object to avoid a lot of
If (myObject == empty)
What is the correct way to do this test? My attempt is to violate the "Virtual Member Calls in the Constructor" rule. Here's my attempt:
Public category animal {public virtual string name {get; Set; } Receive the public virtual string species {}; Set; } Public Virtual Bool Isolol {get {return false; }}} Public Sealed Class NullAnimal: Animals {Public Override String Name {get {return "NULL"; } Set {}} public override string species {return "tap"); } Set {}} Public Virtual Bool Isol {Get {Back Truth; } I agree that you should show patience in these "empty" He said the type of objects, there are some good reasons to do this. On occasion. I also believe that the whole point of an empty object does not need to check whether it is zero or not, so you should lose the IsNull property. If you really feel that you need the IsNull property, then read Viet's reaction again and rethink.
Thanks for more information. Good stuff
Now I will assume that in your actual code you actually have a manufacturer who is trying to determine the name or the values of the species (which can also be called your real code equivalent). Otherwise, why would you get a "virtual member call call builder" warning / error? I have participated in many of these problems while using the new fingerprinted myopropathy {get; Set; } The shortcuts themselves (especially when used in strokes, and I have not started about the serialization version). Your solution is not to use shortcuts, but rather to do it in the old way.
Public category animal {protected animal () {} public animal (string name, string species) {_Name = name; _Species = Species; } Public Virtual String {get {return _Name; } Set {_Name = value; }} Private string _Name; Public virtual string species ({return _Species;} set {_Species = value;}} personal string _Species;} public sealed class NullAnimal: animal {public override string name {{string; blank; return;} set {}} public override string Species {return string.opti;} set {}}}
This solves the problem of installing your virtual properties in the constructor. Instead, you set your own field values Is doing (If you use the shortcut you do not have the ability to refer to) For additional credit, compile both methods, and use the reflector to see the assembly as a result.
The more I use it {get; set;} shortcuts, and I dislike it.
Comments
Post a Comment