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

Started by
2 comments, last by EvilKind 20 years, 9 months ago
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?
I got 2 books, one on game programming and another on miracles so I can understand.
Advertisement
I truely believe it isn''t because I like to give my classes descriptive names
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]
--- krez ([email="krez_AT_optonline_DOT_net"]krez_AT_optonline_DOT_net[/email])
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]

This topic is closed to new replies.

Advertisement