Mutual object interdependency trouble
From: Rune (year)
Date: 01/26/05
- Next message: AlanGLLoyd: "Re: Problem working with an XML DOCUMENT, ClientDataSets and XMLProvider."
- Previous message: Jamie: "Re: Help About wmsdk 9.5"
- Next in thread: Tom de Neef: "Re: Mutual object interdependency trouble"
- Reply: Tom de Neef: "Re: Mutual object interdependency trouble"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Wed, 26 Jan 2005 02:41:53 +0100
I've encountered a problem in the design of a game I'm working on.
I need certain information to be available practically everywhere.
As a simplified example, I have these four resources:
Creature
Level
Maze
Images
Each of them needs all the ones below. The Maze needs the Images (so it can
draw itself); the Level needs the Maze (which it is build after) and the
Images (so it can draw itself); and the Creature needs the Level and Maze
(so it can navigate) and the Images (so it can draw itself). Creature
objects also need data about other Creature objects.
There is no interdependency here. The problem is that it's very cumbersome
to manually have to hand over references to all the needed resources after
new objects are created. It'd be nice if objects after being created could
just fetch the needed references themselves.
This led me to the idea of some kind of Keeper class that keep references to
the various resources. Objects could then just be given a reference to this
Keeper object, and then they could request all needed resources from the
Keeper object.
However, this creates the mutual interdependency. The Keeper class must know
about the four other classes, and the other classes (except the Images
class). must also know about the Keeper class.
As we know, in Delphi classes are bundled in units. As I understand it, a
unit is one big text file that contain one or more classes. Since my game is
big, I have several units to keep a better overview and the four mentioned
classes are all in different units.
The problem is that it seems that in Delphi, if Unit A knows about Unit B,
then Unit B can't know about Unit A. This means that the Keeper concept
doesn't seem to work.
I'm not sure what to do. I've had classes about programming patterns, but
I'm used to Java, not Delphi, and I only have limited practical experience
with complex projects...
Anyone have any ideas?
Rune
-- http://runevision.com
- Next message: AlanGLLoyd: "Re: Problem working with an XML DOCUMENT, ClientDataSets and XMLProvider."
- Previous message: Jamie: "Re: Help About wmsdk 9.5"
- Next in thread: Tom de Neef: "Re: Mutual object interdependency trouble"
- Reply: Tom de Neef: "Re: Mutual object interdependency trouble"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]