Advertisement
jaVer404

level18.lesson08.task01

Nov 4th, 2015
141
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.38 KB | None | 0 0
  1. package com.javarush.test.level18.lesson08.task01;
  2.  
  3. /* Wrapper (Decorator)
  4. Разберись, что делает программа
  5. Аналогично классу DecoratorRunnableImpl создай класс DecoratorMyRunnableImpl
  6. */
  7.  
  8. public class Solution {
  9.  
  10.     public static void main(String[] args) {
  11.         new Thread(new DecoratorRunnableImpl(new DecoratorMyRunnableImpl(new RunnableImpl()))).start();
  12.     }
  13.  
  14.     public static class RunnableImpl implements Runnable {
  15.         @Override
  16.         public void run() {
  17.             System.out.println("RunnableImpl body");
  18.         }
  19.     }
  20.  
  21.     public static class DecoratorRunnableImpl implements Runnable {
  22.         private Runnable component;
  23.  
  24.         public DecoratorRunnableImpl(Runnable component) {
  25.             this.component = component;
  26.         }
  27.  
  28.         @Override
  29.         public void run() {
  30.             System.out.print("DecoratorRunnableImpl body ");
  31.             component.run();
  32.         }
  33.     }
  34.  
  35.     public static class DecoratorMyRunnableImpl  implements Runnable {
  36.         private Runnable component;
  37.         public DecoratorMyRunnableImpl(Runnable component)
  38.         {
  39.             this.component=component;
  40.  
  41.         }
  42.  
  43.         @Override
  44.         public void run()
  45.         {
  46.             System.out.println("DecoratorMyRunnableImpl body ");
  47.             component.run();
  48.         }
  49.     }
  50. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement