I study programming in my college Stamp Coupling. We are learning system analysis and design. My classmate ask me the question, how to solve Stamp Coupling? I ask Teacher who said "Use an interface to limit access from clients", but I still misunderstand.
Well, since the print method needs only the name, address and billing info of the Customer, you don't have to pass anything else to it.
You can define an interface:
public interface PrintableCustomer
{
public ... getName();
public ... getAddress();
public ... getBillingInfo();
}
Now, let the Customer
class implement PrintableCustomer
.
The print method can now accept a PrintableCustomer
instead of a Customer
.
void print (PrintableCustomer customer)
{
...
}
Now print()
only sees the properties that it needs.