Consider I have classes as follows:
public class User{ private String name; //other code private String getName(){ return name; } } public class ShowUserInfo{ public void show(User user){ System.out.println(user.getName()); } }
I’m quite sure I would not have other variations of User, and doesn’t require polymorphism for User. But it is violating the rule of “dependency inversion principle” : ShowUserInfo depends on concrete class User, instead of abstractions. My question is, should I create interface for User:
public interface User{ String getName(); } public class UserImp implements User{ private String name; //other code @Override private String getName(){ return name; } }
even if I don’t need polymorphism and quite sure it would have one type of User only?