V
VisionSet
Person-------->Dog
^ ^
| |
Male--------->ButchDog
Person has a Dog
Male has a ButchDog
If I want to call the Dog types from the Person types polymorphically is it
best style to cast for each call or hide the Dog type with the ButchDog type
in Male with an instance variable eg:
public class A {
X z;
public A(X x) {
z = x;
}
public void doStuff1()
z.stuff();
}
}
class B extends A {
Y z;
public B(Y y) {
super(y);
z = y;
}
public void doStuff2()
z.stuff();
}
}
class X {
public void stuff() {}
}
class Y extends X {
public void stuff() {}
}
// OR...
public class A {
X z;
public A(X x) {
z = x;
}
public void doStuff1()
z.stuff();
}
}
class B extends A {
public B(Y y) {
super(y);
}
public void doStuff2()
((Y) z).stuff();
}
}
TIA
^ ^
| |
Male--------->ButchDog
Person has a Dog
Male has a ButchDog
If I want to call the Dog types from the Person types polymorphically is it
best style to cast for each call or hide the Dog type with the ButchDog type
in Male with an instance variable eg:
public class A {
X z;
public A(X x) {
z = x;
}
public void doStuff1()
z.stuff();
}
}
class B extends A {
Y z;
public B(Y y) {
super(y);
z = y;
}
public void doStuff2()
z.stuff();
}
}
class X {
public void stuff() {}
}
class Y extends X {
public void stuff() {}
}
// OR...
public class A {
X z;
public A(X x) {
z = x;
}
public void doStuff1()
z.stuff();
}
}
class B extends A {
public B(Y y) {
super(y);
}
public void doStuff2()
((Y) z).stuff();
}
}
TIA