October 2017
Intermediate to advanced
396 pages
10h 2m
English
In the following example, I am implementing an Account interface, which can be either a SavingAccount and CurrentAccount or a composition of several accounts. I have a CompositeBankAccount class, which acts as a composite pattern actor class. Let's look at the following code for this example.
Create an Account interface that will be treated as a component:
public interface Account {
void accountType();
}
Create a SavingAccount class and CurrentAccount class as an implementation of the component and that will also be treated as a leaf:
Following is the SavingAccount.java file:
public class SavingAccount implements Account{ @Override public void accountType() { System.out.println("SAVING ...Read now
Unlock full access