ref: http://wiki.tcl.tk/13398
Concepts of OOP:
Objects
Classes
Data Abstraction
Encapsulation
Inheritance
Polymorphism
The main difference between procedural and object oriented programming is that the functional programmer try to split function and data (data structures). But object oriented programmers think in objects that hold data and functions (methods) together in one structure.
The problem with polymorphism means that simply finding a function with the right name is not sufficient, you have to also look at the parameters. Trying to read code without a good class browser is almost impossible. It IS impossible once you get into virtual functions where the decision of which function gets called is only determined at runtime.
For example, suppose you're trying to figure out the following line of code
obj.Write(a);
. Which function is being called? Well, if you're lucky and you know what type obj is then you probably only have about 10 different versions of Write() to pick from depending upon what a is. If you're unlucky and obj can be of several types, then you got a lot of work cut out for you.
ref:http://www.macs.hw.ac.uk/~alison/ds98/node47.html
As objects are normally referenced by pointers, with memory allocated dynamically, there is a small space ovearhead to store the pointers, and a small speed overhead to find space on the heap (at run-time) to store the objects. For dynamic methods there is an additional small time penalty, as the method to choose is found at run time, by searching through the object hierarchy (using the class precedence list for the object). These days, these efficiency penalties seem to be of relatively little importance compared with the software engineering benefits.
Hiç yorum yok:
Yorum Gönder