jeudi 25 avril 2019

Make Interfaces Easy to Use Correctly and Hard to Use Incorrectly - Example

I was reading best practices for developers and found one suggestion is,

Make Interfaces Easy to Use Correctly and Hard to Use Incorrectly

Can anyone describe with minimal sample code to understand the principle. I have tried to search on the internet but did not find any example.

class Account{
    void process(){}
}

interface IBankAccountService {

    boolean check(Account acc);
    void process(Account acc);
}

class ScbAccountService implements IBankAccountService {

    @Override
    public boolean check(Account acc) {
        return true; // check account consistency
    }

    @Override
    public void process(Account acc) {
        acc.process(); // proceed operation
    }
}

Is that above example violating the principle? I so how can I apply this principle in this example.

Aucun commentaire:

Enregistrer un commentaire