concept query in category design

appears as: query, queries, queries, The query
Object Design Style Guide

This is an excerpt from Manning's book Object Design Style Guide.

A modifier method doesn’t really return the information you’re after. In fact, it returns a copy of the whole object, and once you have that copy, you can ask it questions. So modifiers don’t seem to be query methods, but they aren’t traditional command methods either. A command method on an immutable object would imply that it changes the object’s state after all, which isn’t the case. It produces a new object, which isn’t far from just answering a query.

Although it’s stretching the concept a bit, the incremented() method in listing 6.3 could answer the query “give me the current count, but incremented by 1.“

Figure 6.2. There should be no calls to command methods hidden behind a query.
Listing 7.8. changeUserPassword() starts with a query, then performs a task
public function changeUserPassword(
    UserId userId,
    string plainTextPassword
): void {
    user = this.repository.getById(userId);
    hashedPassword = /* ... */;
    user.changePassword(hashedPassword);
    this.repository.save(user);
    this.eventDispatcher.dispatch(
        new UserPasswordChanged(userId)
    );
}