Note that there are some explanatory texts on larger screens.

plurals
  1. PODesign advice - When to use "virtual" and "sealed" effectively
    primarykey
    data
    text
    <p>I'm writing a C# networking library (mostly as a learning exercise, it's not overly important to me if anyone <strong>actually</strong> ends up using it as I'm sure solutions are already out there).</p> <p>I'm fairly happy with my structure so far... I have a few layers of client/server available, that can communicate in raw bytes over sockets, or slightly more complex through serialized message objects.</p> <p>The question (problem?) I'm running into is when exactly I should declare a method, property, or event <code>sealed</code>, <code>virtual</code>, or with no qualifier.</p> <p>I know what all of these do - <code>sealed</code> prevents inheritance of a class, or further overriding of a method. <code>virtual</code> will allow polymorphic behavior via method overriding.</p> <p>Since I'm designing a class library, however, I'm not sure <em>when</em> to use these. It's a question of extensibility, I think... I provide some interfaces, an abstract class or two, and some concrete implementations for consumers of my library to use or extend, but I'm having difficulties deciding when it's a "good idea" to explicitly forbid derivation of a class or to allow overriding functionality.</p> <p>Any general pointers or advice to keep in mind when designing my classes for use by others?</p> <p><a href="https://stackoverflow.com/questions/81052/when-should-a-class-member-be-declared-virtual-c-overridable-vb-net">This question</a> and <a href="https://stackoverflow.com/questions/137260/what-are-the-dangers-of-making-a-method-virtual">this one</a> were somewhat helpful, as was <a href="https://stackoverflow.com/questions/268251/why-seal-a-class">this one</a>, but since I'm writing a distributable library I'm trying to cover all of my bases.</p>
    singulars
    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.
 

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