Search code examples
oopdesign-patternslanguage-agnosticanti-patterns

What's the name of this anti-pattern? Method signature is a liar


What's the name of the antipattern where methods take a generic god-object that has every property you might ever need for a method, rather than explicitly declaring what the method needs?

Eg:

public class BaseRequest
{
    User user;
    Car car;
    CustomerRecords customerRecords;
    Folder folder;
    // ... etc for 10 - 20 other unrelated parameters
}

public void doSomething(BaseRequest request)
{
    User user = request.getUser();
    // do stuff with user, ignore all other attributes of request
}

Instead of

public void doSomething(User user)
{
    // do stuff with user, since it's nice and clear what we want
}

Note - I'm not referring to the Single Responsibility Princple which BaseRequest violates. Instead, I'm looking for the name of the antipattern where the method signature is "lying" about its dependencies.

Also, are there any good blog posts that succinctly explain the evilness of this pattern, which I can point someone to?


Solution

  • Law of Demeter violation