Advertisement

class encapsulation question

Started by January 07, 2001 10:39 AM
1 comment, last by Gaiiden 24 years ago
Okay, I''m making my first game and I''m using OOP. My question is that in my main .cpp file I have the Game_Main() function which carries out all the needed execution statements to make things work by calling the functions of the classes CBall, CBrick, CPaddle, etc. (this is a brick-out clone, btw). Now, the function is very smooth, because every class draws their own stuff onto the screen. But to do this they have to access the backbuffer surface from the main .cpp file. Is this good OOP programming for the class to have to access a surface from the main file or should the main file draw all the objects? ============================== "Need more eeenput..." - #5, "Short Circuit" Blade Edge Software ==============================

Drew Sikora
Executive Producer
GameDev.net

There are a billion and one ways to do a nicely encapsulated program. Your objects need access to each other in order to do anything, so you shouldn''t stress too much about which way round it all happens. The main essence of it is to ensure that nothing sees that which it doesn''t need to see. It isn''t about the files you use, and which things can see stuff in which files, it''s about the scope of your classes. So, to keep it encapsulated, the drawing should be part of the object class, and it just grabs the backbuffer (doesn''t matter where from) as it needs it. To put all the drawing stuff into your main loop would mean the drawing is no longer encapsulated...


Advertisement
Yeah, that''s what i figured. Besides, like I said, my main function is soo nice the way it is as I use expressions for all my conditional statements, which means there is no return variable mangling done from the classes. In fact, now that I think about it, the main function has no variables in it! Any return value from a class function is immediatly evaluated by a conditional statement or loop. How''s that huh??

==============================
"Need more eeenput..."
- #5, "Short Circuit"
Blade Edge Software
==============================

Drew Sikora
Executive Producer
GameDev.net

This topic is closed to new replies.

Advertisement