Should I make my ASP.NET MVC controller actions virtual?

后端 未结 4 378
滥情空心
滥情空心 2021-01-12 05:19

File -> New Project for ASP.NET MVC projects used to generate controllers with virtual actions. I\'m not sure if that stopped with MVC 2 or MVC 3, but is this no longer a be

4条回答
  •  旧巷少年郎
    2021-01-12 06:08

    Generated code may be made virtual for various reasons. It's not good practice to make your own code virtual unless required by some tool. See Liskov Substitution Principle and Open/Closed Principle. I think some frameworks do this to facilitate creating proxies but I can't imagine any reason to make all of your methods virtual. To me it screams copy/paste or cargo cult programmer.

提交回复
热议问题