Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Should the inherited class be in the same cs file of the base class?

I started to learn about inheritance and I was wondering where should I write the derived class. Should it be in the same .cs file as the base class or another .cs file? What is the consensus or norm about this? Does it even matter?

like image 339
user1928470 Avatar asked Nov 01 '25 17:11

user1928470


1 Answers

Personally, I almost always put my derived class in a different files. But, if you use inner class in your code, it's ok to be in the same file. The point is here, Single Responsibility Principle. By that;

  • Reading your code takes less effort.
  • You can simply check multiple classes in different windows at the same time.

Also check Multiple classes in a single .cs file - good or bad?

like image 178
Soner Gönül Avatar answered Nov 03 '25 08:11

Soner Gönül



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!