[DGD]Inherit and include

mtaylor mtaylor at ntlworld.com
Fri May 25 04:49:47 CEST 2001


Dear list :)

I have a little question regarding inherits and includes.... It's probably
going to seem really dumb but here goes:

The way I understand it (and I may embarrass myself by being totally wrong)
when you include a file into a file you are effectively copying the code in
the include file into your other file.
So as a silly example is I have file Z and I include file Y in Z. It's the
same as actually writing the code in Y into my Z file right?

Well I'm a little confused by inheritance...

When you inherit a file does it do the same thing? For example if I inherit
file Y in file Z is it the same as writing all the code in the Y file into
my Z file. Or does it make a reference to the functions in Y.
The reason I am asking is this.... I have something similar to the layout
below (although bigger scale).
We have a player.c which inherits a standard_commands.c (which contains a
switch for all the basic commands, like look, that a player can do). To make
things look pretty and to make finding functions easier we have then split
the actual functions for all the commands into separate files. So the
function for look is in look.c and say is in say.c
The standard_commands.c then inherits all those command files. Now we also
have a tools.c for functions that help in programming (like lowercase etc).
Each command file inherits tools.c

So ... Is each command file copying the tools.c file into itself thus
creating essentially loads of copies of the tools.c code?

Would it be better to have all the commands in one .c file that inherits
tools.c?

Please help ;-)

Just to make it easier to see ...
The diagram of the idea would look like this:

The letters represent the files and the numbers next to the letters
represent arbitrary file sizes (just for the example).

                  A(4)
                  |
-------------------------------------
|           |           |           |
B(10)       C(10)       D(10)       E(10


IDEA: B, C, D and E all inherit A ...

Does this mean that effective file size for each is 14 (making a total disk
space of 56 - i.e. 14*4).
Or do they all reference the file A and therefore total disk space used is
44 i.e. 4*10 + 4 

Hope you can help.
I'm kind of a newbie in this field so please make any answers as simple as
possible ;)



Thanks in advance :)

Matt Taylor


List config page:  http://list.imaginary.com/mailman/listinfo/dgd



More information about the DGD mailing list