teach-ict.com logo

THE education site for computer science and ICT

2. Class

Central to the concept of Object Orientated Programming is the idea of 'Class'.

Picture an object in your mind, such a car - no particular car, but just the idea of a car. In order to have a mental image of it, you inevitably have to consider the features that uniquely identify it as a car.

Something like this:

car

For example it has a certain boxy shape and wheels along with colour, height and width. What we have done is create in our mind an entity called 'car' and have assigned attributes to it.

In object orientated programming this is a 'class'.

A class is a software entity that has internal data attributes and a set of methods that can act upon those attributes.

The pseudocode for creating a 'car' class :-

                                          class Car
                                              private colour
                                              private model
                                              private brand
                                              private speed
                                              private direction

                                            public procedure new (carbrand,carmodel, carcolour)
                                                  brand = carbrand
                                                  model = carmodel
                                                  speed = 0
                                                  direction = 0
                                                  colour = carcolour
                                            endprocedure

                                          endclass

The parts that make up a class is discussed further on the next page.

 

Challenge see if you can find out one extra fact on this topic that we haven't already told you

Click on this link: What is a OOP class