I'm reading J. Bloch
's effective Java and he said the following:
Once an interface is released and widely implemented, it is almost impossible to change.
So, now consider the simple interface for DAO-pattern:
public interface UserDao{
public User getById(int id);
public Collection<User> getAll();
public boolean delete(int userId);
public boolean update(User u);
}
This is how my Dao
interface looked when it was released firstly. By the time, I had to add some functionality to users in order to aggregate all users by its registration_date
or something similar. So, I needed to add corresponding method declarations to the DAO
-interface and implement it.
Moreover for now I can't imagine how DAO
-interfaces may be more or less stable at all, because adding some new DAO
-operations happens very often.
Maybe it's my DAO design disaster, or interfaces are hardly suitable for DAO
s?
I think that sentence of J. Bloch is meant to public interfaces, and not for your DAO case.
Think of you creating a public API to let any programmer use your platform. If you are changing that interface, your are requiring programmers to adapt his code, so this will be frustrating.
But if you are creating an interface for the purpose of your internal app, you are not assuming that risk, and it is worth to evolve your interface as you need.
Obviously you have to consider how many classes implements your interface and assume the cost of the modification.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With