4
Hello, everyone!
Next, I created an abstract class called Tables, where classes of basic tables of the system will inherit from this abstract class. As Neighborhood, City, States, category, etc.. The abstract class code looks like this:
public abstract class Tabelas
{
public int Id { get; set; }
public string Nome { get; set; }
public virtual int IdEstado { get; set; }
public virtual int IdCidade { get; set; }
}
It happens that, for example, the Category class that inherits from the abstract, does not contain the Fields Idestado and Idcidade. But when instantiating it, the object references (accesses) these two properties. The same happens with Classe Bairro, where it is to access only Idcidade, access also Idestado. How to implement this more performatically? I have to create two new abstract classes with Idestado and Idcidade respectively, or not define these two attributes in the abstract class, but define only in the derived class?
I’m sorry if I’ve been confused.
Thank you.
Yeah, you’re confused. Maybe that’s why you’re having trouble understanding. Rethink and try writing in a less confusing way. Then who knows will even understand. The way it is difficult to answer something, would have to guess what you want. Reread the written text. You may have noticed that it does not make much sense what is written. If you tidy up, it is easier to help.
– Maniero
The abstract class should only have methods and properties that should exist in all derivatives. When creating derivatives add those related to it.
– ramaral
I even wonder if you really need an abstract class. As for the fields, inheritance does this, you need to review your modeling concepts for the project by example, it seems to me that you have several objects that need to be identified by type and instance in the system, something like a basic class for everyone (like Object). That’s it?
– Intruso