I have a class C
with lots of members(say 10 members) + members that are only in C
I have two more classes A
and B
which has exactly those above mentioned 10 members. (A and B each does not have those 10 members. Those 10 members are distributed among A and B and A and B has few other fields)
class C {
private int member1;
private String member2;
private String member3;
private float member4;
...
private String member10;
private member11_only_in_C;
private member12_only_in_C;
...
}
class A {
private String memeber10;
private float member4;
private double member6;
....
}
class B {
private int memeber1;
private String memeber2;
private String member7;
....
}
So when I have cObject
I need to set the values of all members in A
and B
like
aObject.setMember10(cObject.getMember10());
bObject.setMember1(cObject.getMember1());
... and so on for all 10 members
This looks bad(long and in future If i add more members to C,A,B I need to write setters for them). So what I thought was If I have class C extend or implement A and B
I can cast
it like
A aObject = (A)cObject;
B bObject = (B)cObject;
But the problems are
- Java does not allow multiple inheritance
- I cannot make
A
andB
as interfaces because I need to set their values. (If I make them as interfaces, their members would becomefinal
, which means that I cannot change their values) - I cannot extend one class and implement other. (I then cannot set values of members of the interface)
What can I do now?
Thanks..