Style/Structuring question: One vs. multiple global objects
Deewiant
deewiant.doesnotlike.spam at gmail.com
Tue Jul 3 10:33:07 PDT 2007
Henning Hasemann wrote:
> Does putting everything in one module really avoid all forward
> reference issues?
No, it doesn't (and that's a good point, that probably wouldn't actually work).
But it solves circular dependencies between modules.
> itile.d:
> interface ITile { }
>
> tile.d:
> import itile;
> import ientity;
> class Tile : ITile { /* use entity via interface here */ }
>
> ientity.d:
> interface IEntity { }
>
> entity.d:
> import ientity;
> import itile;
> class Entity : IEntity { /* use tile here via interface */ }
>
> Yes, for such a case your pattern seems better at least if you dont
> find other reasons for creating IEntity and ITile.
That's the whole point. Entity and Tile are already the absolute base classes,
they just happen to need to be aware of each other. The ITile/IEntities are just
substitutes for C++ header files.
Of course, another way:
class Entity {
Tile t;
}
class Tile {
Object e; // whenever needed, use cast(Entity)e
}
This reminds me a bit of pre-generics Java, actually, where the contents of
Arrays and the like could only be Objects. (Or something like that: I can't
remember exactly.)
--
Remove ".doesnotlike.spam" from the mail address.
More information about the Digitalmars-d-learn
mailing list