jeudi 5 février 2015

A lot derived classes without functonality only to "know" their type

I think there is a better solution for the following problem.


Let's say we have the following structure of classes:



class Foo
{
public int Id { get; set; }
}

class Bar1 : Foo
{

}

class Bar2 : Foo
{

}

class Bar3 : Foo
{

}
//.. A lot more of these Foo derivations


The derived classes has no functionality. The following examples give an idea what the classes are for:



  • Access a specific object from a specific type (object from type Bar3 with Id 5) in a list of Foo objects.

  • Displaying different data in a GUI related to a specific object from type Foo.


Is there a better way to identify one of these objects without derivating them?


Thanks!


Aucun commentaire:

Enregistrer un commentaire