I have a dilemma with this, I am designing a project and basically it will have a baseclass -> entityclass relationship where the entity class inherits from the baseclass. Now the base class is abstract and would have something like:
abstract class MyAbstractClass{
//All this methods need to be implemented
abstract int getHouseId(int id);
abstract string getHouseName(String s);
}
Then I would like to do something like:
public class MyChildClass extends MyAbstractClass{
private int _hId = 0;
private String _hName = "";
public int getHouseId(int id)
{
if(id > _hId)
{
return _hId;
}
return id;
}
public String getHouseName(String s)
{
if(s.Equals(_hName))
{
return _hName;
}
return s;
}
//AND YOU HAVE YOUR SETTERS SOMEWHERE HERE
}
Now please excuse if syntax error, I just made it on the fly, my question is is it better to declare the variables in the abstract class and set and get stuff from there, or create the variables in the child class?. I am confused by it, also if using it in the abstract class, how should they be declared in the abstract class, can I make them private there and add properties to get the values?, or it is better to do it in the child class?. Basically I want to enforce a set of programmers to always use the abstract class as the functions that they HAVE to implement.. just a bit confused about the concept. I tried to google it but did not see many articles about variables and properties in an abstract class, maybe it should be used in the child class. Thank you for your help making me understand this.