Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6043313
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T06:53:09+00:00 2026-05-23T06:53:09+00:00

In a big project I work for, I am considering recommending other programmers to

  • 0

In a big project I work for, I am considering recommending other programmers to always seal their classes if they haven’t considered how their classes should be subclassed. Often times, less-experienced programmers never consider this.

I find it odd that in Java and C# classes are non-sealed / non-final by default. I think making classes sealed greatly improves readability of the code.

Notice that this is in-house code that we can always change should the rare case occur that we need to subclass.

What are your experiences? I meet quite some resistance to this idea. Are people that lazy they could not be bothered to type sealed?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T06:53:10+00:00Added an answer on May 23, 2026 at 6:53 am

    Okay, as so many other people have weighed in…

    Yes, I think it’s entirely reasonable to recommend that classes are sealed by default.

    This goes along with the recommendation from Josh Bloch in his excellent book Effective Java, 2nd edition:

    Design for inheritance, or prohibit it.

    Designing for inheritance is hard, and can make your implementation less flexible, especially if you have virtual methods, one of which calls the other. Maybe they’re overloads, maybe they’re not. The fact that one calls the other must be documented otherwise you can’t override either method safely – you don’t know when it’ll be called, or whether you’re safe to call the other method without risking a stack overflow.

    Now if you later want to change which method calls which in a later version, you can’t – you’ll potentially break subclasses. So in the name of “flexibility” you’ve actually made the implementation less flexible, and had to document your implementation details more closely. That doesn’t sound like a great idea to me.

    Next up is immutability – I like immutable types. I find them easier to reason about than mutable types. It’s one reason why the Joda Time API is nicer than using Date and Calendar in Java. But an unsealed class can never be known to be immutable. If I accept a parameter of type Foo, I may be able to rely on the properties declared in Foo not to be changed over time, but I can’t rely on the object itself not being modified – there could be a mutable property in the subclass. Heaven help me if that property is also used by an override of some virtual method. Wave goodbye to many of the benefits of immutability. (Ironically, Joda Time has very large inheritance hierarchies – often with things saying “subclasses should be immutable. The large inheritance hierarchy of Chronology made it hard to understand when porting to C#.)

    Finally, there’s the aspect of overuse of inheritance. Personally I favour composition over inheritance where feasible. I love polymorphism for interfaces, and occasionally I use inheritance of implementation – but it’s rarely a great fit in my experience. Making classes sealed avoids them being inappropriately derived from where composition would be a better fit.

    EDIT: I’d also like to point readers at Eric Lippert’s blog post from 2004 on why so many of the framework classes are sealed. There are plenty of places where I wish .NET provided an interface we could work to for testability, but that’s a slightly different request…

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I work in the maintenance team of a big project (around 7k+ classes) and
I currently work into a big project that consists of lots of classes. Can
Starting a new big C multiplatform project, what rules should one follow to avoid
I've got a big-ish project that needs a lot of work on a new
I work on a big project in company. We collect data which we get
I work on a big Flash project as the web backend guy that delivers
We’re coming to a big release in a web project I work on, and
I have a big project that was first created in Borland C++ 6. We're
I have a big project compiled into libProject.so-file (shared library), I made some modules
I want to start working on a big project. I research about performance issues

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.