I did a few searches (maybe I'm not describing my problem well enough), but could not find an answer for this
Let's say you have the following POCO:
public class StandardObject
{
public string A {get;set;}
public string B {get;set;}
}
Elsewhere in the program, there is some logic for handling StandardObjects. There is a case where sometimes a standard object can be handled differently. We know this when we create a StandardObject, however, none of the current properties can be used to determine this further down the chain. One approach would be to add and set a flag or enumeration type in a standard object and verify this when handling objects. For instance.
if(standardObject.IsSpecial){...}
if(standardObject.ObjectType == StandardObjectTypeEnum.Special){...}
This does not seem to be the best approach.
Another option is to create a derived class:
public class SpecialObject : StandardObject { }
Now, instead of checking the property, we can check the type. For instance.
if(standardObject.GetType() == typeof(SpecialObject)){...}
( , , -)
, SpecialObject StandardObject. . , (E.G. SpecialObject), . .
. , . , , , , , StandardObject SpecialObject , ? , ?
:
:
, , , ,
EDIT:
, -, . , , :
- Object - , , DTO
- StandardObject.
- , StandardObject
- - .
- , StandardObject ""
, "" , StandardObject, , - StandardObject