Advertisement
Guest User

Untitled

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