Stamp Coupling Improvement

481 Views Asked by At

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. enter image description here enter image description here

1

There are 1 best solutions below

0
On BEST ANSWER

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.