you said
the client inherits from "Entity", this "Entity" accepts "Customer" as T, but this client is not an "entity"
This makes no sense because it is what inherits. He establishes an "eat" relationship. So in fact Customer
is Entity
Sorry this was based on code in which generics were allocated, because it was not in the code block.
The same principle is still valid. This is a bit confusing because it looks like a recursive definition, but it is not.
Think about it as Customer
inherits from Entity
. As it happens, there are methods or fields that depend on the most common parameter, for example. Customer
. I am not familiar with NHibernate, so I don’t know what the rest of Entity<T>
looks like, but I suppose it has some methods that use its own type as a general parameter.
Say for example, it has a method called
public IEnumerable<T> GetEntities()
which returned a list of its own instances. He needs this method to return a specific type, not a base type. So in the class Customer
this method will be
public IEnumerable<Customer> GetEntities<Customer>()
If it did not have a common parameter, it could return an IEnumerable<Entity>
This is just an example of how it can be used, I don’t know how it was really used.
source share