Urgent.News

What's breaking now, across thousands of outlets.

Tech

Sealed Isn't a Restriction, It's a Promise

Leaving a class open to inheritance is a design decision, not a default you can ignore. The core idea An unsealed class is a promise: every virtual member can be overridden without breaking what the class guarantees. Most classes never meant to make that promise. They're just unsealed by default, because that's what class gives you unless you say otherwise. Common mistake: treating sealed as "I…

The article "Sealed Isn't a Restriction, It's a Promise" discusses the importance of using the sealed keyword in class design. The author emphasizes that leaving a class open to inheritance, even if not intended, can lead to unexpected behavior and bugs at runtime. By using the sealed keyword, developers can ensure that the class's invariants are maintained and that any virtual members cannot be overridden, preventing potential issues.

The example provided illustrates how a class designed to prevent negative balances becomes vulnerable when sealed, as the compiler catches the mistake and prevents the runtime error.

Brief written by urgent.news from Dev.to's own syndicated text. Machine-written — may contain errors; check the original before relying on it.

Read the original at dev.to →

More in Tech

The Problem I Saw From the Floor, Not From a Laptop

Why I started building Materia AI before it was anywhere near finished. There's a specific kind of bad moment that happens on a restaurant floor. A table orders the salmon. You put it in.

  • Waitstaff unaware of kitchen shortages until service begins
  • Reporter's real-life observation inspired Materia AI creation
  • Backend of Materia AI successfully implemented, frontend in development

More from Friday 28 August →