次のインターフェースについて考えてみましょう。
public interface Cat{
public Object getCat();//returns any type of object
}
public interface DomesticCatInterface{
public String somethinOnlyRelatedToDomesticCat();
}
public interface WildCatInterface{
public String somethinOnlyRelatedToWildCat();
}
public class DomesticCat implements Cat, DomesticCatInterface{
@Override
public DomesticCat getCat(){
return this;
}
@Override
public String somethinOnlyRelatedToDomesticCat(){
return "something";
}
}
public class WildCat implements Cat, WildCatInterface{
@Override
public WildCat getCat(){
return this;
}
@Override
public String somethinOnlyRelatedToWildCat(){
return "something";
}
}
クラスから参照を取得する必要がある場合、これは良い習慣に従いますか?