Wednesday, March 3, 2010

Interface naming

Some not so good examples of interface naming are:

interface PersonDS{}

PersonDSEJB implements PersonDS {}

class User implements IUser {}

The first example shows how ugly and meaningless it can be when you are forced to implement an interface by the framework.

In the second example the prefix hurts readability. On top of that, when changing from an abstract class to an interface, a coding convention with prefix implies renaming all the occurrences of the class.

There is also another convention, used by many open source projects including Spring

interface User {}

class DefaultUser implements User {}

class AnotherClassOfUser implements User {}

Much better :)

No comments:

Post a Comment