home *** CD-ROM | disk | FTP | other *** search
/ APDL Public Domain 2 / APDL_PD2A.iso / magazines / _tyrant2 / pages / page8 < prev    next >
Encoding:
Text File  |  1995-05-27  |  3.1 KB  |  78 lines

  1. >POSITION 20,1900
  2. >SIDE Left
  3. >STYLE Heading
  4. OOP Programming
  5. >STYLE Body
  6. If you have read any of my other articles you will probably wonder whether I am
  7. capable of doing anything but criticising the Acorn market.  However, one of the
  8. interesting new developments is the availability of C++ and therefore an OOP
  9. language on the Acorn.
  10.  
  11. So what does OOP stand for?  Well actually it is Object Orientated
  12. Programming.  Not very helpful is it?  To understand OOP you also need to
  13. understand 'procedual' programming.
  14.  
  15. Programming in languages which are of a high level such as BASIC have
  16. resulted in very structured languages.  They are usually structured using
  17. procedual programming.  This consists of grouping bits of the program together
  18. and calling them when needed.  If you like they are the "verbs" of programming.
  19. By this I simply mean they are actions.  For example are procedure might be
  20. called "add", "find" or "input".  As I am referring to the C++ OOP system from
  21. now on we shall call these procedures "functions".
  22.  
  23. Going back to the point that functions are verbs, objects are very simply nouns.
  24. To an experienced programmer this will sound strange and even by looking at
  25. example you will ask, "So why not use functions?"  The idea is that it is possible
  26. to model the real world inside a computer.  You can't do this by using functions.
  27. If you take everything in this magazine and only read to verbs it will mean
  28. nothing to you.  You have to relate all the verbs to nouns.  It may sound
  29. confusing so let us look at an example:
  30.  
  31. I am writing a program about a car inside a computer using functions.  How am
  32. I supposed to do it?  Simply by taking the cars actions I cannot describe so I
  33. must resort OOP. Firstly non-programmers must be very sure of what it meant
  34. by variables.  A variable is simply something which stores information.  The
  35. name of the variable then points to this information.  The example should
  36. display this.
  37. The program:
  38. >STYLE Code
  39. car
  40. { varibles are:
  41.         name
  42.         colour
  43.         age
  44.         size
  45.        
  46.   functions are:
  47.   display details
  48.   enter details
  49. }
  50. >STYLE Body
  51. >SIDE Right
  52. >POSITION 1300,2000
  53. This is a very simple program.  It is not real C++ code but is very similar.  From
  54. now on it gets very techinical and difficult.
  55.  
  56. This is example not called an object but a class.  In reality this is the template
  57. for an object.  So to create an object I would write:
  58. >STYLE Code
  59. car object1
  60. >STYLE Body
  61. The word car creates an object called "object1".  This could in fact be any name
  62. you wished providing it follows a few guidelines from the C++ language.  I can
  63. now call the "enter details" function:
  64. >STYLE Code
  65. object1.enter details
  66. >STYLE Body
  67. This would now call a standard function of this name and prompt the user for
  68. car details and place them in the variables as follows:
  69. >STYLE Code
  70. object1.name="Vauxhall"
  71. object1.colour="Green"
  72. >STYLE Body
  73. and so on.  A "display data" functions could be used to display the data.  It
  74. could simply print it on the screen or even if more details were received build a
  75. computer generated picture inside the machine depending on how adventurous
  76. you are!
  77.  
  78. So OOP is just a way of modelling the real world.