Results 1 to 4 of 4

Thread: Two parents should know the same subclass

  1. #1

    Two parents should know the same subclass

    i have a weird problem.. i'm making a new design to my game engine but this design needs to be more object oriented than the last one i scrapped so i want my texturemanager and modelmanager to have access to a virtual file system class. but how can i make that these classes have access to the same instance of this filesystem? they are two child classes which are owned by another "higher class"..

    :? -HELP-...

    Regards Jeppe
    Peregrinus, expectavi pedes meos in cymbalis
    Nullus norvegicorum sole urinat

  2. #2
    Legendary Member cairnswm's Avatar
    Join Date
    Nov 2002
    Location
    Randburg, South Africa
    Posts
    1,537

    Two parents should know the same subclass

    To share an instance of the class indicates that they are not children of that class but that there are several different objects being used.

    [pascal]
    TextureManager := TTextureManager.Create;
    LightingManager := TLightingManager.Create;

    FileSystem := TFileSystem.Create;
    TextureManager.FileSystem := FileSystem;
    LightingManager.FileSystem := FileSystem;
    [/pascal]

    This means that a FileSystem is created and each of the other objects can use the information available in that FileSystem Object.
    William Cairns
    My Games: http://www.cairnsgames.co.za (Currently very inactive)
    MyOnline Games: http://TheGameDeveloper.co.za (Currently very inactive)

  3. #3

    Two parents should know the same subclass

    Should the filesystem variable in texturemanager and modelmanager then be a pointer or a variable?

    well i'll try that! Thanks

    regard Jeppe
    Peregrinus, expectavi pedes meos in cymbalis
    Nullus norvegicorum sole urinat

  4. #4

    Two parents should know the same subclass

    Quote Originally Posted by JSoftware
    Should the filesystem variable in texturemanager and modelmanager then be a pointer or a variable?

    well i'll try that! Thanks

    regard Jeppe
    A "class" already is a reference (read: pointer).

    The trick if multiple classes have references to the same class is to think (and document/annotate) clearly which class "owns" the object for e.g. freeing purposes.

    So if X,Y,Z both reference A, we specify that e.g. X also OWNS A, so when X gets destroyed, in its destructor it free's A.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •