home *** CD-ROM | disk | FTP | other *** search
- >POSITION 20,1900
- >SIDE Left
- >STYLE Heading
- OOP Programming
- >STYLE Body
- If you have read any of my other articles you will probably wonder whether I am
- capable of doing anything but criticising the Acorn market. However, one of the
- interesting new developments is the availability of C++ and therefore an OOP
- language on the Acorn.
-
- So what does OOP stand for? Well actually it is Object Orientated
- Programming. Not very helpful is it? To understand OOP you also need to
- understand 'procedual' programming.
-
- Programming in languages which are of a high level such as BASIC have
- resulted in very structured languages. They are usually structured using
- procedual programming. This consists of grouping bits of the program together
- and calling them when needed. If you like they are the "verbs" of programming.
- By this I simply mean they are actions. For example are procedure might be
- called "add", "find" or "input". As I am referring to the C++ OOP system from
- now on we shall call these procedures "functions".
-
- Going back to the point that functions are verbs, objects are very simply nouns.
- To an experienced programmer this will sound strange and even by looking at
- example you will ask, "So why not use functions?" The idea is that it is possible
- to model the real world inside a computer. You can't do this by using functions.
- If you take everything in this magazine and only read to verbs it will mean
- nothing to you. You have to relate all the verbs to nouns. It may sound
- confusing so let us look at an example:
-
- I am writing a program about a car inside a computer using functions. How am
- I supposed to do it? Simply by taking the cars actions I cannot describe so I
- must resort OOP. Firstly non-programmers must be very sure of what it meant
- by variables. A variable is simply something which stores information. The
- name of the variable then points to this information. The example should
- display this.
- The program:
- >STYLE Code
- car
- { varibles are:
- name
- colour
- age
- size
-
- functions are:
- display details
- enter details
- }
- >STYLE Body
- >SIDE Right
- >POSITION 1300,2000
- This is a very simple program. It is not real C++ code but is very similar. From
- now on it gets very techinical and difficult.
-
- This is example not called an object but a class. In reality this is the template
- for an object. So to create an object I would write:
- >STYLE Code
- car object1
- >STYLE Body
- The word car creates an object called "object1". This could in fact be any name
- you wished providing it follows a few guidelines from the C++ language. I can
- now call the "enter details" function:
- >STYLE Code
- object1.enter details
- >STYLE Body
- This would now call a standard function of this name and prompt the user for
- car details and place them in the variables as follows:
- >STYLE Code
- object1.name="Vauxhall"
- object1.colour="Green"
- >STYLE Body
- and so on. A "display data" functions could be used to display the data. It
- could simply print it on the screen or even if more details were received build a
- computer generated picture inside the machine depending on how adventurous
- you are!
-
- So OOP is just a way of modelling the real world.