Archived

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

EvilKind

Is it good practise to put more than one class in a source file?

Recommended Posts

EvilKind    122
Is it good practise to put more than one class in a source file? I personally have mainly used the OO language Eiffel along with BON and so far have always used a class for a source file. Now seeing more then one class in a C++ source file has surprise me. I can see that it''s fewer files to look at but is this good practise?

Share this post


Link to post
Share on other sites
Guest Anonymous Poster   
Guest Anonymous Poster
I truely believe it isn''t because I like to give my classes descriptive names

Share this post


Link to post
Share on other sites
krez    443
generally, no (IMHO of course)... but sometimes if i have several small related classes i put them into one header & source file (i.e. CTextureManager, CTexture, and the various helper structs) because anything that uses one will use all of them.

just my 2 cents

[edited by - krez on July 8, 2003 7:39:09 PM]

Share this post


Link to post
Share on other sites
Way Walker    745
In general, put them in their own files. The two cases you'll probably have more than one class per .h/.cpp pair are

1) A large class with a helper class (A resource manager is a good example, maybe a linked list or tree with nodes as a seperate object, etc.)

2) A bunch of small, related classes (think < functional > from the C++ library)

The idea is to have one "idea" per .h/.cpp pair.

[edited by - Way Walker on July 8, 2003 12:56:39 AM]

Share this post


Link to post
Share on other sites