According to Understanding "programming to an interface", as I understand, I think I should depend on abstract class only. However, in some case, for example, Student
:
public class Student {
private String name;
private int age;
}
to modify it so that it becomes depend on abstract class only (which MyIString
may be a new abstract class that wraps String
):
public class Student {
private MyIString name;
private java.lang.Number age;
}
I think the modified one is more complex. And a more "real" example, say Address
:
public class Address {
private ZipCode zipcode;
}
which I need one type of ZipCode
only, but if I modify it as:
public class Address {
private IZipCode zipcode;
}
which IZipCode
is an interface, then I think it may mislead other teammates that there would have other types of ZipCodes
.
I think the cases above becomes more complex and less maintainable if I was allowed a class to use abstract class members only. So my question is, should I still follow "programming to an interface not implementation" if the "followed" one becomes more complex (in my view)?
java.lang.String
in place of all the objects! Your functions will just interpret the String to obtain the information and the instructions to execute and you wont need any other type thanString
! That's clearly going too far in using concrete types.