Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Footballer {
- String name;
- Role role;
- public Footballer(String name, Role role) {
- this.name = name;
- this.role = role;
- }
- void executeMove() {
- this.role.executeMove();
- }
- }
- interface Role {
- void executeMove();
- }
- class Gatekeeper implements Role {
- @Override
- public void executeMove() {
- System.out.println("dive");
- }
- }
- class Defender implements Role {
- @Override
- public void executeMove() {
- System.out.println("dispossess");
- }
- }
- class Midfielder implements Role {
- @Override
- public void executeMove() {
- System.out.println("pass");
- }
- }
- class Striker implements Role {
- @Override
- public void executeMove() {
- System.out.println("shoot");
- }
- }
- public class Main {
- public static void main(String[] args) {
- Footballer f1 = new Footballer("Tatarusanu", new Gatekeeper());
- Footballer f2 = new Footballer("Ronaldo", new Striker());
- f1.executeMove();
- f2.executeMove();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement