Max_Leb

Untitled

Mar 18th, 2022
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.63 KB | None | 0 0
  1.  
  2. interface IQuackStrategy {
  3.     void quack();
  4. }
  5.  
  6. class NormalQuack implements IQuackStrategy {
  7.     public void quack() {
  8.         System.out.println("quack");
  9.     }
  10. }
  11.  
  12. class SquiqQuack implements IQuackStrategy{
  13.     public void quack(){
  14.         System.out.println("squiq");
  15.     }
  16. }
  17.  
  18. class SilentQuack implements IQuackStrategy {
  19.     public void quack() {
  20.        
  21.     }
  22. }
  23.  
  24. interface ISwimStrategy {
  25.     void swim();
  26. }
  27.  
  28. class NormalSwim implements ISwimStrategy {
  29.     public void swim() {
  30.         System.out.println("angry swimming splashes");
  31.     }
  32. }
  33.  
  34. class CuteSwim implements ISwimStrategy {
  35.     public void swim(){
  36.         System.out.println("cute swimming splashes");
  37.     }
  38. }
  39.  
  40. class NoSwim implements ISwimStrategy {
  41.     public void swim() {
  42.        
  43.     }
  44. }
  45.  
  46. interface DisplayStrategy{
  47.     void display();
  48. }
  49.  
  50. class mallardDisplay implements DisplayStrategy{
  51.     public void display(){
  52.         System.out.println("Mallard goes meee");
  53.     }
  54. }
  55.  
  56. class RubberDuckDisplay implements DisplayStrategy{
  57.     public void display(){
  58.         System.out.println("Rubber goes hoo");    
  59.     }
  60. }
  61.  
  62. class RedHeadDisplay implements DisplayStrategy{
  63.     public void display(){
  64.         System.out.println("RedHead goes woo");
  65.     }
  66. }
  67.  
  68. class NoDisplay implements DisplayStrategy{
  69.     public void display(){
  70.     }
  71. }
  72.  
  73. interface FlyStrategy{
  74.     void fly();
  75. }
  76.  
  77. class NormalFly implements FlyStrategy{
  78.     public void fly(){
  79.         System.out.println("flying");
  80.     }
  81. }
  82.  
  83. class SlowFly implements FlyStrategy{
  84.     public void fly(){
  85.         System.out.println("flying slowly");
  86.     }
  87. }
  88.  
  89. class FastFly implements FlyStrategy{
  90.     public void fly(){
  91.         System.out.println("flying fast");
  92.     }
  93. }
  94.  
  95. class NoFly implements FlyStrategy{
  96.     public void fly(){
  97.         System.out.println("cannot fly");
  98.     }
  99. }
  100.  
  101.  
  102. public class Duck {
  103.     private IQuackStrategy quackStrategy;
  104.     private ISwimStrategy swimStrategy;
  105.     private DisplayStrategy displayStrategy;
  106.     private FlyStrategy flyStrategy;
  107.    
  108.     public Duck(IQuackStrategy quackStrategy, ISwimStrategy swimStrategy, DisplayStrategy displayStrategy, FlyStrategy flyStrategy) {
  109.         this.quackStrategy = quackStrategy;
  110.         this.swimStrategy = swimStrategy;
  111.         this.displayStrategy = displayStrategy;
  112.         this.flyStrategy = flyStrategy;
  113.     }
  114.    
  115.     public void Qauck() {
  116.         quackStrategy.quack();
  117.     }
  118.    
  119.     public void Swim() {
  120.         swimStrategy.swim();
  121.     }
  122.    
  123.     public void Display(){
  124.         displayStrategy.display();
  125.     }
  126.    
  127.     public void Fly(){
  128.         flyStrategy.fly();
  129.     }
  130. }
  131.  
Advertisement
Add Comment
Please, Sign In to add comment