Checkstyle AbstractClassName check: Reasons for labeling classes ending in "Factory"

Checkstyle " AbstractClassName " check uses the following default template to check the names of classes that should be declared as abstract:

^Abstract.*$|^.*Factory$ 

I understand that classes starting with 'Abstract' must be declared abstract. But why is this also true for classes ending in "Factory"?

Is this really the best practice? And if so, what should I call factory classes instead?

+4
source share
2 answers

The default regular expression came from the Abstract Factory template - see http://www.apwebco.com/gofpatterns/creational/AbstractFactory.html .

I admit that I have not seen this naming convention used in the wild. A simple change to the verification configuration to use the template:

 ^Abstract.*$ 

As always, Checkstyle should be used as a guide to best practices.

+4
source

A small extension for Oliver's answer (it was not easy to add as a comment). To modify the Checkstyle rule so that it no longer checks the "Factory", put the following in the checkstyle configuration XML file:

 <module name="AbstractClassName"> <property name="format" value="^Abstract.*$"/> </module> 

See here for more details.

+2
source

Source: https://habr.com/ru/post/1402849/


All Articles