Pass the Object, Please

This sign-in method looks reasonable:

public HomePage SignInPage.SignIn(String userName, String password)

It isn’t reasonable.

Why? Because it violates encapsulation: the caller knows (or thinks it knows) what’s needed for signing in.

What if a scanned-in card id is added to the sign-in procedure? Well, that would require the method to be changed.

But actually, that’s none of the caller’s business in the first place.

This is reasonable:

public HomePage SignInPage.SignIn(User user)

Moral: don’t pass multiple data items from an object. Pass the object!

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s