Archived

This topic is now archived and is closed to further replies.

cclements

Public members vs. TypeDef Struct

Recommended Posts

I have seen all DirectDraw stuff encapsulated within a structure. I was thinking of putting everything in a class with all public members. I know these are essentially the same. Which is better programming practice? --Chris

Share this post


Link to post
Share on other sites
It is better programming practice to leave it like it is otherwise you will create bloatware and use unnessicary code.

-----------------------------

A wise man once said "A person with half a clue is more dangerous than a person with or without one."

Share this post


Link to post
Share on other sites
I would put it in a class.......
put all data members as private and provide public member functions that allow the manipulation of the private data members....why do this ?
say if you have a class called DDSurface.....for data members you have LPDIRECTDRAWSURFACE7 mySurface;
you could make this public, but in this case whoever is using the class could manipulate the surface in some harmful way....like accidentally deleting it or something like that when the only thing you intended for it to do was draw to the surface......
so instead make a function
HRESULT DDSurface::drawToScreen(xPos, yPos);
that will let whoever is using the class to draw the surface to the screen and keep them from doing harmful operations on the private data member while at the same time all they have to do is call this function to draw to the screen.......
instead of......

BltFast->something->something(bunch of variables);
do some other stuff and error check;

........to draw something


"Now go away or I shall taunt you a second time"
- Monty Python and the Holy Grail
themGames Productions

Share this post


Link to post
Share on other sites
There''s no different between using a struct and a class with all public members. They function the same. Although making all public members mean you miss out on a lot of the benefits of classes. Perhaps read up on object orientation before you start throwing things haphazardly into classes in the name of ''good programming practice''.

By the way, you don''t need to typedef a struct in C++. Just name it whatever you want it to be called, eg:

struct MyStructName
{
// members
};

Share this post


Link to post
Share on other sites