Permalink
Show file tree
Hide file tree
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
12 changed files
with
265 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
/* | ||
* To change this license header, choose License Headers in Project Properties. | ||
* To change this template file, choose Tools | Templates | ||
* and open the template in the editor. | ||
*/ | ||
package simuduck; | ||
|
||
/** | ||
* | ||
* @author aa6164 | ||
*/ | ||
abstract class Duck { | ||
|
||
protected FlyBehaviour flyBehaviour; | ||
protected QuackBehaviour quackBehaviour; | ||
|
||
public abstract void display(); | ||
|
||
public void swim() { | ||
System.out.println("I am swimming!"); | ||
} | ||
|
||
public void performFly() { | ||
flyBehaviour.fly(); | ||
} | ||
|
||
public void performQuack() { | ||
quackBehaviour.quack(); | ||
} | ||
|
||
public void setFlyBehaviour(FlyBehaviour behaviour) { | ||
this.flyBehaviour = behaviour; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
/* | ||
* To change this license header, choose License Headers in Project Properties. | ||
* To change this template file, choose Tools | Templates | ||
* and open the template in the editor. | ||
*/ | ||
package simuduck; | ||
|
||
/** | ||
* | ||
* @author aa6164 | ||
*/ | ||
public interface FlyBehaviour { | ||
public void fly(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
/* | ||
* To change this license header, choose License Headers in Project Properties. | ||
* To change this template file, choose Tools | Templates | ||
* and open the template in the editor. | ||
*/ | ||
package simuduck; | ||
|
||
/** | ||
* | ||
* @author aa6164 | ||
*/ | ||
public class FlyNoWay implements FlyBehaviour { | ||
|
||
@Override | ||
public void fly() { | ||
System.out.println("I cannot fly!"); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
/* | ||
* To change this license header, choose License Headers in Project Properties. | ||
* To change this template file, choose Tools | Templates | ||
* and open the template in the editor. | ||
*/ | ||
package simuduck; | ||
|
||
/** | ||
* | ||
* @author aa6164 | ||
*/ | ||
public class FlyWithWings implements FlyBehaviour { | ||
|
||
@Override | ||
public void fly() { | ||
System.out.println("I am flying with wings!"); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
/* | ||
* To change this license header, choose License Headers in Project Properties. | ||
* To change this template file, choose Tools | Templates | ||
* and open the template in the editor. | ||
*/ | ||
package simuduck; | ||
|
||
/** | ||
* | ||
* @author aa6164 | ||
*/ | ||
public class MallardDuck extends Duck { | ||
|
||
public MallardDuck() { | ||
super.flyBehaviour = new FlyWithWings(); | ||
super.quackBehaviour = new Quack(); | ||
|
||
System.out.println("Created a Mallard Duck"); | ||
} | ||
|
||
@Override | ||
public void display() { | ||
System.out.println("Displays a Mallard Duck"); | ||
} | ||
|
||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
/* | ||
* To change this license header, choose License Headers in Project Properties. | ||
* To change this template file, choose Tools | Templates | ||
* and open the template in the editor. | ||
*/ | ||
package simuduck; | ||
|
||
/** | ||
* | ||
* @author aa6164 | ||
*/ | ||
public class MuteQuack implements QuackBehaviour { | ||
|
||
@Override | ||
public void quack() { | ||
System.out.println("Mute quack..."); | ||
} | ||
|
||
|
||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
/* | ||
* To change this license header, choose License Headers in Project Properties. | ||
* To change this template file, choose Tools | Templates | ||
* and open the template in the editor. | ||
*/ | ||
package simuduck; | ||
|
||
/** | ||
* | ||
* @author aa6164 | ||
*/ | ||
public class Quack implements QuackBehaviour { | ||
|
||
@Override | ||
public void quack() { | ||
System.out.println("I am quacking!"); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
/* | ||
* To change this license header, choose License Headers in Project Properties. | ||
* To change this template file, choose Tools | Templates | ||
* and open the template in the editor. | ||
*/ | ||
package simuduck; | ||
|
||
/** | ||
* | ||
* @author aa6164 | ||
*/ | ||
public interface QuackBehaviour { | ||
public void quack(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
/* | ||
* To change this license header, choose License Headers in Project Properties. | ||
* To change this template file, choose Tools | Templates | ||
* and open the template in the editor. | ||
*/ | ||
package simuduck; | ||
|
||
/** | ||
* | ||
* @author aa6164 | ||
*/ | ||
public class RedheadDuck extends Duck { | ||
|
||
public RedheadDuck() { | ||
super.flyBehaviour = new FlyWithWings(); | ||
super.quackBehaviour = new Quack(); | ||
|
||
System.out.println("Created a Redhead Duck"); | ||
} | ||
|
||
@Override | ||
public void display() { | ||
System.out.println("Displays a Redhead Duck"); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
/* | ||
* To change this license header, choose License Headers in Project Properties. | ||
* To change this template file, choose Tools | Templates | ||
* and open the template in the editor. | ||
*/ | ||
package simuduck; | ||
|
||
/** | ||
* | ||
* @author aa6164 | ||
*/ | ||
public class RubberDuck extends Duck { | ||
|
||
public RubberDuck() { | ||
super.flyBehaviour = new FlyNoWay(); | ||
super.quackBehaviour = new Squeak(); | ||
|
||
System.out.println("Created a Rubber Duck"); | ||
} | ||
|
||
@Override | ||
public void display() { | ||
System.out.println("Displays a Rubber Duck"); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
/* | ||
* To change this license header, choose License Headers in Project Properties. | ||
* To change this template file, choose Tools | Templates | ||
* and open the template in the editor. | ||
*/ | ||
package simuduck; | ||
|
||
/** | ||
* | ||
* @author aa6164 | ||
*/ | ||
public class Squeak implements QuackBehaviour { | ||
|
||
@Override | ||
public void quack() { | ||
System.out.println("I make a squeak noise!"); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
/* | ||
* To change this license header, choose License Headers in Project Properties. | ||
* To change this template file, choose Tools | Templates | ||
* and open the template in the editor. | ||
*/ | ||
package simuduck; | ||
|
||
/** | ||
* | ||
* @author aa6164 | ||
*/ | ||
public class WoodenDuck extends Duck { | ||
|
||
public WoodenDuck() { | ||
super.flyBehaviour = new FlyNoWay(); | ||
super.quackBehaviour = new MuteQuack(); | ||
|
||
System.out.println("Creates a wooden duck"); | ||
} | ||
|
||
@Override | ||
public void display() { | ||
System.out.println("Displays a wooden duck!"); | ||
} | ||
|
||
} |