Advertisement
Guest User

Untitled

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