Improve method interfaces by renaming, separating queries from modifiers, and introducing parameter objects. Trigger: When cleaning up method signatures, implementing CQRS, or reducing parameter lists.
This skill enables the agent to improve the interfaces of class methods. By simplifying how methods are called and what they return, the agent reduces the mental load for developers and makes the system's internal API more intuitive and robust.
createOrder(), renderCustomerInfo()).private or protected to reduce the public surface area.setHeight(val) instead of setValue('height', val)).DateRange instead of separate start and end dates).-1), throw specific exceptions to separate normal execution flow from error handling.// BEFORE: Method gets data AND changes state (side effect)
getTotalOutstandingAndSetReady(): number {
this.isReady = true; // Modifier
return this.calculateTotal(); // Query
}
// AFTER: Responsibilities split
getTotalOutstanding(): number {
return this.calculateTotal();
}
setReady(): void {
this.isReady = true;
}
// BEFORE: Repeating group of parameters
amountInvoicedIn(start: Date, end: Date): number { /* ... */ }
amountOverdueIn(start: Date, end: Date): number { /* ... */ }
// AFTER: Parameters grouped into an immutable object
class DateRange {
constructor(
public readonly start: Date,
public readonly end: Date
) {}
}
amountInvoicedIn(range: DateRange): number { /* ... */ }
amountOverdueIn(range: DateRange): number { /* ... */ }
// BEFORE: Returning special values for errors
withdraw(amount: number): number {
if (amount > this.balance) return -1;
this.balance -= amount;
return 0;
}
// AFTER: Using proper exception handling
withdraw(amount: number): void {
if (amount > this.balance) {
throw new InsufficientFundsError();
}
this.balance -= amount;
}