The system of static typing is your friend. Yes, I know arguments for dynamic typing, but that's a different issue. The point I'm making is that, if you're using a statically typed language, e.g. Java, use the type system to your benefit. Don't pass around generic objects; create a specific type, instead. This type can be implemented with the FlyweightPattern, but it has a distinct type.
Contrast this signature
void assignCustomerToSalesman(Long customerId, Long salesmanId);versus
void assignCustomerToSalesman(CustomerId customerId, SalesmanId salesmanId);or even:
void assignCustomerToSalesman(Customer customer, Salesman salesman);or even:
class Salesman { ... void assignCustomer(CustomerId customerId);The latter three have no possibility of getting the arguments in the wrong order.
I've been looking for a name for this, and haven't found one. I'm proposing SpecificTypingPattern. --GeorgeDinwiddie
This SoftwareDevelopmentGuideline is related to the NullObject pattern.
See also: CompilerErrorsAreYourFriends, WholeValuePattern, StronglyTypedCollection, StaticTypeSafety