October 2017
Intermediate to advanced
396 pages
10h 2m
English
Let's look at the following code to demonstrate the Decorator design pattern.
Create a component class:
Following is the Account.java file:
package com.packt.patterninspring.chapter3.decorator.pattern;
public interface Account {
String getTotalBenefits();
}
Create concrete components classes:
Following is the SavingAccount.java file:
package com.packt.patterninspring.chapter3.decorator.pattern;
public class SavingAccount implements Account {
@Override
public String getTotalBenefits() {
return "This account has 4% interest rate with per day $5000 withdrawal limit";
}
}
Let's create another concrete class for Account component:
Following is the CurrentAccount.java file:
package com.packt.patterninspring.chapter3.decorator.pattern; ...
Read now
Unlock full access