Mail Archives: djgpp/1997/11/26/14:35:36
Ingo Ruhnke wrote:
>
> Mike Coulson <Mike AT mcoolie DOT demon DOT co DOT uk> wrote
> > What is object orientated programming and in what way does it differ
> > from normal C.
> >
> > Thanks for any replies,
> >
> > Mike.
>
> Take a look at
> http://www.icce.rug.nl/docs/cpp.html
> and
> http://info.desy.de/gna/html/cc/
> maybe this should be enough for beginning
>
> Ingo
Object Oriented Programming mainly means that programmers like to work
with objects that are known and understood by there customers.
Instead of:
char *name, *address, *city; int age;
it is easier to just say:
PERSON p;
In a lot of cases objects are named by the information they contain.
Example: PERSON contains data about an individual.
PERSON is then a struct with something extra (read on).
In C you could define this kind of behaviour also:
typedef PERSON struct { char *name, *address ... };
In C++ also operations (methods) are defined as part of an object.
class PERSON {
char *name, *address, *city;
int age;
// Methods
void define_person(PERSON& p) {
p.name = "Mike";
p.address = "Hell Street";
...
}
}; // end of class
The nice thing of these operations is that they actually form the
interface to the object. For a programmer it is no longer necessary to
know all data-members from the class. If the functions
user_input_person(), print_person(); compare_person(); are available (as
methods of the class) it is possible to work with a sorted list of
persons.
The C++ compiler not only checks if your code is good, it also checks if
the methods are valid for the object you want to use them on. This
prevents bad or unclear programming.
- Raw text -