Code scattering

Code scattering means crosscutting concerns are duplicated across all modules of an application. Let's look at the following example to understand code scattering:

public class TransferServiceImpl implements TransferService {
public void transfer(Account source, Account dest, Double amount) {
//permission check
if (!hasPermission(user) {
throw new AuthorizationException();
}
}
}

public class AccountServiceImpl implements AccountService {
public void withdraw(Account userAccount, Double amount) {
//Permission check
if (!hasPermission(user) {
throw new AuthorizationException();
}
}

As we saw in preceding code sample, the permission check (security) is our crosscutting concern that is duplicated in all services.

These code tangling and code scattering problems are solved by AOP, but how? We will see shortly.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset