//interfaces
public interface Singer{
void sing();
}
public interface SongWriter{
void writeSong();
}
//Implementations
public class PureSinger implements Singer{
void sing(){}
}
public class SingerSongWriter implements Singer, SongWriter{
void sing(){}
void writeSong(){}
}
//Client code
void methodA(){
Singer objPureSinger = new PureSinger();
Singer objSingerSWer = new SingerSongWriter();
doSomething(objPureSinger);
doSomething(objSingerSWer);
}
public void doSomething(Singer obj){
obj.sing();
obj.writeSong(); //<--- this does not work.
}
In order to acheve this type of code, how should I design the class structure?
Aucun commentaire:
Enregistrer un commentaire