Database and Delphi..

Look, most OO languages are going to contain your procedural code; although the code will be organised into objects.

Objects are intended to mimic real world objects, for example:

You have an object that is an animal (this is our class). You also have objects that are cows and dogs (these are subclasses). Since cows and dogs are both animals they have similar characteristics; they both inherit some characteristics from this animal object. However, cows and dogs are not the same thing, but they do have the same parent (namely they are both animals).

Now, for example we can say that all animals have four legs and the make some sort of a noise. These are attributes of an animal, or rather your class variables. We know that every animal has four legs, but we don't know what noise they make (only that they make a noise).

So since the cow is an animal it has four legs and makes a noise. When we define the cow object we say the type of noise is a "moo". Similarly with the dog, it has four legs and makes a noise, which is a "woof". Since the noise attribute is different for a cow and dog they are not the same thing.

Notice how in the above example we never need to say that a dog or cow has four legs? That is because they are types of animal, and we know ALL animals have four legs. As such we save on programming time, and possible errors, by reusing parts of the parent (animal) object/classes and only defining in the child (dog, cow) subclasses the parts that make them different.

Easy peasy :D

EDIT: if you had been using a purely procedural language you would need to define everything about the dog and cow (and cat, and horse, and sheep) every single time.
Yo thank you for that i understand it better now...:D
 
Yo thank you for that i understand it better now...:D

Of course it gets a bit more technical.

You need to understand 3 main concepts:

  • Inheritance: a dog and cow inherit their "template" from animal; such as their four legs and the fact that they make some sort of noise
  • Encapsulation: we have a method makeNoise() for both cow and dog; once the type of noise the cow or dog makes is defined we merely call makeNoise() and get an answer of "moo" or "woof". As such, someone using the dog or cow class doesn't need to know what noise is returned, just that a noise of some sort will be returned. These details are hidden from someone using the class
  • Polymorphism: since both dog and cow are of the animal class they can be collectively put together. If we have an array of the animal class we can store dogs and cows in this array. When we retrieve the classes (dog or cow) from the array we check if they are of type cow or dog; once we determine this we can tell the programme to accept the class as a cow or a dog. As such we don't need to store dogs and cows in separate cow and dog arrays, but rather a single animal array.

Find some decent definitions for these three concepts and drill them into your head. Academically they are the most important concepts of OO programming. In time you will understand how they work and why they are important.

Good luck!
 
Top
Sign up to the MyBroadband newsletter
X