Person has an "is a" relationship with Entity, this means if A is a Person then A is an Entity, always. When assigning a more derived (Person is more derived than Entity, sometimes said Person inherits or is based on Entity) the compiler will attempt to find and use a lossless conversion between Person and Entity and because of the "is a" relationship there is a single cast operation which will do this.
The cast does not alter the memory layout of the Person. The cast does not create a new Entity. The cast takes the typed reference and attempts to return a new valid differently typed reference. This will succeed and you will obtain a new reference to the same original memory area which you will now access through a different Type. No data loss, no data alteration, no data multiplication or creation. The only thing that changes is a single new reference and your view of the data you have. User defined cast operations can perform data changes and interpretations but i advise you against worrying about that until you need them.
If my "person" entity has additional storage of FirstName and Surname, can I call an undo on the base class?....
Person derives from Entity therefore Person "is a" Entity is always true. This rule is not reversible. If i create a new class Pet which derives from Entity then Pet "is a"n Entity but a Pet is not a Person. An entity "may be" any of the types derived from it.
If and only if an Entity is also a Person then a cast operation to the more derived type will succeed. If Entity is not a Person then an InvalidCastException will be thrown. Because the cast operations do not change the data in the object the data in a Person is not lost zeroed or otherwise altered when you cast it to an Entity. For the same reason if you successfully cast an Entity into a Person then the data for that person remains unchanged from when you last accessed it as a Person instance.
These are reasonably fundemental language principles. If you don't understand this you're not seeing the flexibility and power of the language or the framework and you should consider doing some reading about object orientation and object polymorphism as well as the c# language docs.
I'd say your fellow experts aren't OOP programers (maybe expert sequential programmers? RPG? Cobol?), or they aren't experts. Yes, and Wraith implied, this is the tip of the iceburg.
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.