sometimes, it need implement two interfaces, like:
[code]
public interface IAface {
public static final String A = "AFACE";
public int doSmile();
}
public interface IBface {
public static final String B = "BFACE";
public String doSmile();
}
[/code]
usually, it can be done like:
[code]
public class Face implements IAface, IBface {
public int doSmile() {
...
}
public String doSmile() {
...
}
}
[/code]
then Java compile will complain on can't different those two methods which you must implement in your concrete class, so here have two choices:
1. if those two interfaces are own by you, then you can change the signature of those methods
2. otherwise, you can write a abstract class first like:
[code]
public abstract class MyAface implements IAface {
public int doSmile() {
return -1;
}
public abstract int myDoSmile();
}
[/code]
then let your concrete class extends your abstract class and implements IBface again like:
[code]
public class Face2 extends MyAface implements IBface {
public int myDoSmile() {
...
}
public String doSmile() {
...
}
}
[/code]
this fix the name conflict, but lost interface value because when do like:
[code]
IAface aface = new Face2();
aface.doSmile(); //ok
aface.myDoSmile(); //can't do like this
[/code]
it may even worse when you haven't the right to change source code of IAface and IBface, so seems pay attention to naming in programming is so important :(, but sometimes it can't guarantee all names won't conflict especially when you want to extend/implement others' code
what's your insight?
[code]
public interface IAface {
public static final String A = "AFACE";
public int doSmile();
}
public interface IBface {
public static final String B = "BFACE";
public String doSmile();
}
[/code]
usually, it can be done like:
[code]
public class Face implements IAface, IBface {
public int doSmile() {
...
}
public String doSmile() {
...
}
}
[/code]
then Java compile will complain on can't different those two methods which you must implement in your concrete class, so here have two choices:
1. if those two interfaces are own by you, then you can change the signature of those methods
2. otherwise, you can write a abstract class first like:
[code]
public abstract class MyAface implements IAface {
public int doSmile() {
return -1;
}
public abstract int myDoSmile();
}
[/code]
then let your concrete class extends your abstract class and implements IBface again like:
[code]
public class Face2 extends MyAface implements IBface {
public int myDoSmile() {
...
}
public String doSmile() {
...
}
}
[/code]
this fix the name conflict, but lost interface value because when do like:
[code]
IAface aface = new Face2();
aface.doSmile(); //ok
aface.myDoSmile(); //can't do like this
[/code]
it may even worse when you haven't the right to change source code of IAface and IBface, so seems pay attention to naming in programming is so important :(, but sometimes it can't guarantee all names won't conflict especially when you want to extend/implement others' code
what's your insight?