Below are the two variants of defining and declaring an identical interface. The interface is essentially the same but only differs in the way it is coded.
Snippet-1
------------
public interface UserManager {
public abstract void addUser(User user);
public abstract void removeUser(User user);
//blah blah
}
Snippet-2
------------
public interface UserManager {
void addUser(User user);
void removeUser(User user);
//blah blah
}
Snippet-1 is more detailed or explicit in terms of access specifiers whereas Snippet -2 is implicit in terms of access specifiers. Now the question to be asked here is how should we define interfaces in our code. I did look at the Java Coding standards and there was nothing much I could find over there.
Essentially even though they differ in the way it is coded the access specifiers are public and abstract implicitly even if you dont specify them explicitly according to the Java Language Specification. In my opinion I think its good practice and more clear if you define interfaces and its methods explicity the way its done in Snippet-1 as opposed to Snippet-2. What does the readers of my blog have to say about this? Please share your opinions about the same!!
Thursday, January 3, 2008
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment