Guest User

Untitled

a guest
Mar 24th, 2018
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.25 KB | None | 0 0
  1. //---------------------------abstraction--------------------------------
  2.  
  3. // when we translit the object from real world to our class
  4. // we chose only the fatures witch e need in our class
  5. // for example create a class "Rectangle", and we need 4 variables for it description
  6. // they are coordinates of high left corner, width and height.
  7.  
  8. class rect{
  9. float x,y,w,h;
  10. void draw(){}
  11. }
  12.  
  13. // but such features as color and material are not important for my task
  14.  
  15. //---------------------------polymorphism-------------------------------
  16.  
  17. // the interface methods can be implemented in many ways
  18. // for example we have the interface "activity" and a method "doingActivities"
  19.  
  20. interface activity{
  21. string doingActivities();
  22. }
  23.  
  24. // it implements to the objects "workers"
  25. // as each worker can do different activities, each of them implement the method
  26. // "doingActivities" in different ways
  27.  
  28. class BuildWorker implements activity{
  29. @overrite
  30. string doingActivities(){
  31. return "can Build";
  32. }
  33. }
  34.  
  35. class CookWorker implements activity{
  36. @overrite
  37. string doingActivities(){
  38. return "can Cook";
  39. }
  40. }
  41.  
  42. //---------------------------encapsulation-------------------------------
  43.  
  44. // we need to hide some part of our code.
  45.  
  46. class MyObject{
  47. private double mass;
  48. public double price;
  49. }
  50.  
  51. // so that some variables and methods can not be changed;
  52. // for example we have object with mass as public parametr.
  53.  
  54. class MyObject{
  55. public double mass;
  56. public double price;
  57. }
  58.  
  59. // and someone has set it -12.
  60. // As the mass can not less then 0 the problems can appear
  61.  
  62.  
  63. //---------------------------inheritance--------------------------------------
  64.  
  65. // this allows to use an existion code from another class
  66. // for example:
  67.  
  68. class LampBulb {
  69. float power;
  70. void shine();
  71. }
  72.  
  73. class LedLampBulb extends LampBulb{
  74. string [] someElectronics;
  75. }
  76.  
  77. class FluorescentTubes extends LampBulb{
  78. string HighVoltageElectronics;
  79. }
  80.  
  81. // extendsed classes LedLampBulb and FluorescentTubes also have variable "power"
  82. // and method "shine" from class LampBulb
  83.  
  84. //---------------------------Delegation-------------------------------
  85.  
  86. // is when cthe class transmit some part of it work to other classes
  87. // for instance the Boss has got some order and allocate it between workers
Add Comment
Please, Sign In to add comment