Is it poor practice to identify objects via an enumeration property, instead of using GetType()?
Posted
by
James
on Stack Overflow
See other posts from Stack Overflow
or by James
Published on 2011-11-17T09:38:31Z
Indexed on
2011/11/17
9:51 UTC
Read the original article
Hit count: 124
I have a collection of objects that all implement one (custom) interface: IAuditEvent
.
Each object can be stored in a database and a unique numeric id is used for each object type.
The method that stores the objects loops around a List<IAuditEvent>
, so it needs to know the specific type of each object in order to store the correct numeric id.
Is it poor practice to have an enumeration property on IAuditEvent
so that each object can identify itself with a unique enumeration value?
I can see that the simplest solution would be to write a method that translates a Type
into an integer, but what if I need an enumeration of audit events for another purpose? Would it still be wrong to have my enumeration property on IAuditEvent
?
© Stack Overflow or respective owner