Skip to content

[New Rule] Method chaining in class design MUST be avoided #25

Closed
@lenaorobei

Description

@lenaorobei

Rule

Method chaining in class design MUST be avoided.

Reason

Source: Magento Technical Guidelines.

According to technical guidelines:

Application SHOULD be structured in compliance with the CQRS principle.

Good explanation of why method chaining contradicts this principal was described by Martin Fowler in the "Domain-Specific-Languages" book:

Command-query separation is an extremely valuable principle in programming, and I strongly encourage teams to use it. One of the consequences of using Method Chaining in internal DSLs is that it usually breaks this principle - each method alters state but returns an object to continue the chain. I have used many decibels disparaging people who don't follow command-query separation, and will do so again.

Suggested Implementation Direction

Detect return $this; in methods.

Metadata

Metadata

Assignees

No one assigned

    Labels

    acceptedNew rule is acceptednew ruleNew feature implementationtechnical guidelinesThe rule is based on Magento Technical Guidelines

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions