Skip to main content
GameDev.net gamedev.net
🔒 Locked

Design question...

Started by ShaderDev Jul 30, 2006 at 1:59 PM 2 replies 950+ views
Original Post
ShaderDev
ShaderDev
Hello, I’m writing a game engine and there is a thing bothering me...i have a main object "root object" which acts as an interface for creating/removing other objects like the renderer, the file manager, windows and etc. The idea is these objects to be created only from this root object and not individually by the programmer...currently I’m making the object constructors and destructors protected and making the root object a friend class, however i think that this screws encapsulation and stuff...i was just wondering if there is a better way of doing that?
FlaiseSaffron
FlaiseSaffron
The friend declarations break the extensibility of your root object, but otherwise if you declare key functions as virtual, you should get what you're looking for.
JohnBolton
JohnBolton
Is there is a good reason to prevent outside creation? If there is, then the root object is already closely-coupled by design, and your implementation necessary.

But as pointed out by Lukewarm, if the objects can only be created by the root object, then they are no longer extendable. My advice is to make the constructors public unless there is a good reason not to.

John BoltonLocomotive Games (THQ)Current Project: Destroy All Humans (Wii). IN STORES NOW!

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.