Introduction to Object-oriented Programming

All of the code you have been producing so far has used the structured approach to programming. Structured programming is characterised by the following features:

  • The breaking down of a main problem into sub-problems
  • The use of functions or procedures to solve these sub-problems
  • The use of both global and local variables to store data
  • The use of parameters to pass data to the functions or procedures

Object-oriented programming develops these concepts further by bundling functions/procedures and their required data together into a single unit.

Let's look at an example:

This tutorial

In order to get to grips with object-oriented programming we are going to develop simple simulations that will make use of your existing knowledge of real world objects, such as crops and animals.

Simulations are a useful way to introduce this topic as one of the advantages of object-oriented programming is that it helps us to model the real world more closely. By making simple simulations we will be able to see clearly just how OOP helps us in this regard.

In addition, simulation is one of the topics that you must cover at A-Level (AQA specification):

  • Be familiar with a simulation as a computer program or network of computers that attempts to simulate a model of a particular system
  • Know that computer simulations can represent real and imaginary situations
  • Know that simulations allow users to study or try things that would be difficult or impossible to do in real life

Therefore, we can learn about simulations in a practical way by developing a simple one using an object-oriented approach.

The farm game scenario

These tutorials focus on the development of simple crop, animal and field simulations. The intention is to give you some of the building blocks that would be required to create a farm management game similar to the types that are popular on social networking site or the 'Tycoon' series of games.

We will not be developing the whole game but let us consider some of elements of a farm:

An overview on the objects required for the farm game

Now that we have some understanding of what is involved it is time to dive in and start programming the required objects.