Skip to content

Files

Latest commit

 

History

History
29 lines (18 loc) · 916 Bytes

BuilderMethodWithSideEffects.md

File metadata and controls

29 lines (18 loc) · 916 Bytes

Pattern: Builder method with side effects

Issue: -

Description

A builder method is defined as one that creates objects. As such, they should never be of void return type. If a method is named build, create, or make, then it should always return a value.

This rule has one property: methodNameRegex. The default value is (make.*|create.*|build.*). Update this property if you have some other naming convention for your builder methods.

Example of violations:

class SomeClass {

        void make() { /* ... */ }
        void makeSomething() { /* ... */ }

        void create() { /* ... */ }
        void createSomething() { /* ... */ }

        void build() { /* ... */ }
        void buildSomething() { /* ... */ }
}

Further Reading