Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Class Questions
Message
From
20/01/1999 21:33:08
 
 
To
20/01/1999 20:49:54
General information
Forum:
Visual FoxPro
Category:
Classes - VCX
Title:
Miscellaneous
Thread ID:
00177951
Message ID:
00178351
Views:
28
>I would add to Vlad's response that when A is derived from B, A and B are both in memory, but A's contents are much smaller then B's because A contains a reference to B and instructions on what changes were made in B to produce A.

I don't know it for sure, but I don't believe A contains a reference for B. I would say that B is embeded in A (from the memory point of view).

>When you instantiate A and test for memmory used, the derive A from B, the amount of memory used is much less than double. Clearly then A is referencing B for a lot of the information used to create A.
>
>What that tells me is that if I create B then derive one instance from it, I have actually used up more memory than if I just used B instead of deriving A from it and using A. But if I derive A, C, D, E, and F., the memory savings are considerable over using B five times.

To have a more precise terminology: A class is a patern. An object is an instance of a class. A class can be derived from another class. An object cannot be derived from something else. An object is created based on the definition of a class.

When we have 2 or more objects based on the same class, each object uses its own memory.

When class A is derived from class B and obB is an object, instance of class A: obB takes the necessary amount of memory specified by the pattern A. A inherits methods and properties from B. obB does not inherit anything. It just has everything that is specified by its A class. I mean: inheritance "happens" at pattern/class level and not at object level.

It's all like in real life: we have words for objects. Each word is a class. The actual objects are not words, they simply are what they are. When we can identify the word for an object, we know some characteristics of that object. For ex., knowing that an object is a Ford, we know that it has a small "Ford" label on the back, etc. We also know that a Ford is a car and this tells us that a Ford has all the characteristics of a car. So, a Ford is derived from Car. It's true that the "Ford" word makes a reference to "Car", but a Ford object doesn't have this reference. It simply is a Car.

The difference between classes and objects is important because their models are different. Classes are concepts, objects are objects :). It's true that in a specific language implementation, objects of the same class can make references to a common memory area that keeps information about their class (especially for method invocation). In particular, each class may keep reference(s) to its base class(es). But this is not mandatory and each object may have its own private memory area for everything it needs.

So, when we derive A, C, D, E, and F classes from B, we save the code that is reused from B at development time. At runtime, if we instantiate an object from each of these classes, each object will occupy the memory space for a B + the memory space for what was added in the derived class. These objects do not share the memory space for B. The only thing they can share is B's method invocation table. But I don't know how is this implemented in VFP, so...

Vlad
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform