Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <blockquote> <p>In C# you have to mark method as virtual to make it possible to override. Does it mean that in C# you should mark all methods virtual (except a few ones that you don't want to be overridden), since most likely you don't know in what way your class can be inherited?</p> </blockquote> <p>No. If the language designers thought that virtual should have been the default then <strong>it would have been the default</strong>.</p> <p>Overridablility is a <em>feature</em>, and like all features it has <em>costs</em>. The costs of an overrideable method are considerable: there are big design, implementation and testing costs, particularly if there is any "sensitivity" to the class; virtual methods are ways of introducing untested third-party code into a system and that has a security impact.</p> <p>If you don't know how you intend your class to be inherited then <em>don't publish your class</em> because <em>you haven't finished designing it yet.</em> Your extensibility model is definitely something you should know ahead of time; it should deeply influence your design and testing strategy. </p> <p>I advocate that all classes be <em>sealed</em> and all methods be <em>non-virtual</em> until you have a real-world customer-focussed reason to unseal or to make a method virtual. </p> <p>Basically your question is "I am ignorant of how my customers intend to consume my class; should I therefore make it arbitrarily extensible?" No; you should <em>become knowledgable</em>! You wouldn't ask "I don't know how my customers are going to use my class, so should I make all my properties read-write? And should I make all my methods read-write properties of delegate type so that my users can replace any method with their own implementation?" No, don't do any of those things until you have <em>evidence</em> that a user actually needs that capability! Spend your valuable time designing, testing and implementing features that users actually want and need, and do so from a position of knowledge.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload