java - Same getters and setters in 2 child classes..? -
i'm not oo design .. please bear me..
i have class a, , 2 classes extend a. both of them have same fields.. better, have getter / setters in or have same getter / setters in both kid classes.. or there improve way this..?
this have done (mock)..
class a{ private int x; protected a(int x){ this.x = x; } public static createa(id a, int x){ switch(a){ case 0: homecoming new c(x); break; //so on } public int getx(){ homecoming x; } }
thanks..
this depends on classes
if properties property of yes, if it's chance have same properties no.
basicly question need inquire is, there ever class extends doesn't need properties.
if reply no, set them on a,
if reply yes, maintain them on sub-classes, or create abstract class in between 2 subclasses, having these 2 properties.
java oop inheritance
No comments:
Post a Comment