object oriented programming and its use 
Author Message
 object oriented programming and its use

this is what we are studying now and i dont know what the heck it is for.
isnt it the same as wehn we use records??? i know that we can use procedure
and functions with objects but why would we want to??? also why do we need
different names eg procedures=methods
much thanx to any1 who can help me with the answer



Wed, 18 Jun 1902 08:00:00 GMT  
 object oriented programming and its use


[object oriented programming and its use]

Quote:
> this is what we are studying now and i dont know what the heck it is for.
> isnt it the same as wehn we use records??? i know that we can use
procedure
> and functions with objects but why would we want to???

And I bet when you learned about For loops the first time you didn't see
what you could do with them either :)

Static procedure and function methods are like procedures and functions
working on records, true. But it's a little more flexible: if you create a
descendant object type the ancestor's methods will still work.

But when you get to polymorphism (ie virtual methods), objects can do things
which get quite awkward with records. You can write a procedure which takes
an object instance as a parameter, and then calls its virtual methods to do
things to or with it. Next week, you add a new object type to your program,
by creating a descendant object type, overriding the virtual methods - and
if you do it right, the function will still work, with both object types.
Now, the amazing thing about that is, your function will call one set of
procedures (the original virtual methods) if you pass in last week's object,
but if you pass in this week's object, it will choose to call a different
set of procedures (the overridden methods) - which did not exist when the
function was written. And it does this without having been modified! In a
big project, the ability to modify and extend a program and have the rest of
the program adapt without you having to work on it can be quite nice.

Note: this old procedure or function which takes on new behaviour can be a
method. In fact, methods should be written this way: if there is a method
for accessing object data, it should be used even by other methods, in
preference of directly accessing the data.

Now, it's true you can do this with records. A friend of mine used to do it
with ANSI C, which does not have objects either. You just have procedure and
function variables in your record. But having the machinery inside the
compiler is a bit more efficient and easier to use. Why do you have record
types? Anything you can do with them you can do in other languages that
don't have them - but it would be more difficult, so Pascal has records.
Same here with objects.

Quote:
> also why do we need
> different names eg procedures=methods

The term "method" is more about who owns them. You still call them
procedures and functions, but they are procedures and functions that are
part of an object. You can also have procedures and functions which are not
methods but which do operate on the object, e.g. ordinary procedures and
functions which take an object as a parameter  - the term "Method" helps us
to know that we are not talking about these.

Quote:
> much thanx to any1 who can help me with the answer


Please look for the answer on comp.lang.pascal.borland :)

FP



Wed, 18 Jun 1902 08:00:00 GMT  
 object oriented programming and its use

Quote:
> this is what we are studying now and i dont know what the heck it is for.
> isnt it the same as wehn we use records??? i know that we can use procedure
> and functions with objects but why would we want to??? also why do we need
> different names eg procedures=methods
> much thanx to any1 who can help me with the answer

Lots of reasons:

(1) The procedures and functions are tied to the variable they manipulate.

(2) Objects allow for polymorphism. You can think of polymorphism a little
like evolution, where a basic descendant type contains the basic methods and
properties (fields) common to many, more specialized decendants.

(3) Other things that I can't think of just now.

Polymorphism is the real power behind objects. You should get a book and learn
more about OOP as it's the "modern" way to write programs.

No. If you can't be bothered to read the newsgroup you post a question to, I
can't be bothered to email you a reply.  This is not a pizza delivery service.

--
Jay

Jason Burgon - Author of Graphic Vision
New version 2 now available from:
http://www.jayman.demon.co.uk



Wed, 18 Jun 1902 08:00:00 GMT  
 object oriented programming and its use

Quote:
> this is what we are studying now and i dont know what the heck it is
for.
> isnt it the same as wehn we use records??? i know that we can use
procedure
> and functions with objects but why would we want to??? also why do
we need
> different names eg procedures=methods
> much thanx to any1 who can help me with the answer


Hello,
Little question:
Each time you use a different car,
would you like to read a whole new manual, just to know how to use it?
I hope not.
You (the person object) have a set of genes (properties or whatever
they are called in the different languages),
Each time you will get a child, (a new person object) will inherit
those genes,
and every time this child will have another child those genes will go
with it,
and so you can go on and on.
That's called inheritance.
Now, you might say: but my child will not have all of my genes, it
will also inherit some genes of my partner ( a different person
object):
Well, that's polymorphism

A kind of different behaviour on the same basic person object:
If you tell a 'soldier-object' to shoot or you tell a
'European_football_player-object' to shoot,
they will both shoot but the result wouldn't be the same
(of course I would prefer to be a European_keeper-object
in stead of an 'enemy_soldier-object' in this case)

I know I have oversimplified things,
but it should give an idea of the possibilities a programmer has when
using objects.

Hope I made you think about it,
Marcel



Wed, 18 Jun 1902 08:00:00 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. Desperate help on Object-oriented programming (turbo pascal)

2. Object Oriented Programming Tutorials

3. Object Oriented Programming Tutorials

4. Object oriented programming

5. Books about Object Oriented Programming in BP7.

6. OOP - books about object oriented programming in BP7.

7. Object-Oriented Databases for Delphi

8. serialun.zip Turbo Pascal Object Oriented Serial Port Unit

9. The object-oriented tool for EVERY Pascal programmer.

10. Possible Object Oriented Compiler Error.

11. Object Oriented Examples

12. curious: relational vs object oriented databases

 

 
Powered by phpBB® Forum Software