Menu

#556 UseSingletonRule: too restrictive in some cases

open
pmd (543)
5
2012-10-07
2006-08-03
No

Hi,

we have a base class with 1 static helper method in.

public class BaseDao extends BaseObject {

// protected constructor to prevent other classes
// making instances of this class directly
protected BaseDao() {
    super();
}

protected static String load(String file) {
    ... // load something from the file
}

}

Concrete implementations extends from this base class:

public class PersonDao extends BaseDao {

private static final String SQL =

load("selectperson.sql");

public PersonDao() {
    super();
}

public Person findPerson(String id) {
    ...
}

}

The UseSingletonRule triggers on the BaseDao class, but
it shouldn't!

Perhaps the UseSingletonRule class could ignore classes
that:
- extend from another class, or
- has a protected constructor

what do you think?

regards,
Maarten

Discussion


Log in to post a comment.