Is it a bad practice to have multiple classes in the same file?

后端 未结 15 2268
眼角桃花
眼角桃花 2020-12-08 03:48

I used to have one class for one file. For example car.cs has the class car. But as I program more classes, I would like to add them to the same file. For

15条回答
  •  暗喜
    暗喜 (楼主)
    2020-12-08 04:20

    In Java, one public class per file is the way the language works. A group of Java files can be collected into a package.

    In Python, however, files are "modules", and typically have a number of closely related classes. A Python package is a directory, just like a Java package.

    This gives Python an extra level of grouping between class and package.

    There is no one right answer that is language-agnostic. It varies with the language.

提交回复
热议问题