Skip to main content
gamedev.net
🔒 Locked

Class design

Started by alaa_m Oct 30, 2002 at 4:07 PM 0 replies 200+ views
Original Post
alaa_m
alaa_m
I was just wondering if it''s a good class design to destroy and finalize everything in the class destructor even if there are methods to do so. for example, suppose a DirectPlay encapsulation class. Should I put code that for example closes all connections, destroy players and so on or have the class''s client to call on these methods before they destroy the class?! pDPlay->Host(...); ... //destruction pDPlay->Close(...); pDPlay->finalize... delete pDPlay; - or - just delete pDPlay; and destructor takes care of finalyzing things What is the best design? thx Alaa,
Alaa,
the_grip
the_grip
i imagine this is situational, but here''s what i would recommend:

Give the class a ::Cleanup(), ::Close(), ::Delete(), etc. function, and allow it to be called if necessary. Then you would have a flag variable that indicates if the class is in a "closed" state or if it is active (i.e. memory is allocated internally, etc.). In the destructor, the class could check the flag to see if it needs to clean itself up.

That''s what i would recommend - program for both needs, but use which one makes sense in particular situations.

"You call him Dr. Grip, doll!"
"You call him Dr. Grip, doll!"

Topic Locked

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

Sign in to reply to this topic.