Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- interface IQuackStrategy {
- void quack();
- }
- class NormalQuack implements IQuackStrategy {
- public void quack() {
- System.out.println("quack");
- }
- }
- class SquiqQuack implements IQuackStrategy{
- public void quack(){
- System.out.println("squiq");
- }
- }
- class SilentQuack implements IQuackStrategy {
- public void quack() {
- }
- }
- interface ISwimStrategy {
- void swim();
- }
- class NormalSwim implements ISwimStrategy {
- public void swim() {
- System.out.println("angry swimming splashes");
- }
- }
- class CuteSwim implements ISwimStrategy {
- public void swim(){
- System.out.println("cute swimming splashes");
- }
- }
- class NoSwim implements ISwimStrategy {
- public void swim() {
- }
- }
- interface DisplayStrategy{
- void display();
- }
- class mallardDisplay implements DisplayStrategy{
- public void display(){
- System.out.println("Mallard goes meee");
- }
- }
- class RubberDuckDisplay implements DisplayStrategy{
- public void display(){
- System.out.println("Rubber goes hoo");
- }
- }
- class RedHeadDisplay implements DisplayStrategy{
- public void display(){
- System.out.println("RedHead goes woo");
- }
- }
- class NoDisplay implements DisplayStrategy{
- public void display(){
- }
- }
- interface FlyStrategy{
- void fly();
- }
- class NormalFly implements FlyStrategy{
- public void fly(){
- System.out.println("flying");
- }
- }
- class SlowFly implements FlyStrategy{
- public void fly(){
- System.out.println("flying slowly");
- }
- }
- class FastFly implements FlyStrategy{
- public void fly(){
- System.out.println("flying fast");
- }
- }
- class NoFly implements FlyStrategy{
- public void fly(){
- System.out.println("cannot fly");
- }
- }
- public class Duck {
- private IQuackStrategy quackStrategy;
- private ISwimStrategy swimStrategy;
- private DisplayStrategy displayStrategy;
- private FlyStrategy flyStrategy;
- public Duck(IQuackStrategy quackStrategy, ISwimStrategy swimStrategy, DisplayStrategy displayStrategy, FlyStrategy flyStrategy) {
- this.quackStrategy = quackStrategy;
- this.swimStrategy = swimStrategy;
- this.displayStrategy = displayStrategy;
- this.flyStrategy = flyStrategy;
- }
- public void Qauck() {
- quackStrategy.quack();
- }
- public void Swim() {
- swimStrategy.swim();
- }
- public void Display(){
- displayStrategy.display();
- }
- public void Fly(){
- flyStrategy.fly();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment