DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports Events Over 2 million developers have joined DZone. Join Today! Thanks for visiting DZone today,
Edit Profile Manage Email Subscriptions Moderation Admin Console How to Post to DZone Article Submission Guidelines
View Profile
Sign Out
Refcards
Trend Reports
Events
Zones
Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
  1. DZone
  2. Coding
  3. Frameworks
  4. Should I make a class final?

Should I make a class final?

Yaozong Zhu user avatar by
Yaozong Zhu
·
Nov. 21, 12 · Interview
Like (0)
Save
Tweet
Share
1.19K Views

Join the DZone community and get the full member experience.

Join For Free

One question comes out of my mind for several times recently. Should I make a class final if I know there’s no use case to inherit it? I think it’s a good practice to mark a class final if you want the class behavior immutable to some extent. But this view holds true until the popularity of AOP.

Speaking of Spring AOP, it’s based on running time proxy-based model. If the original class implements any Interface(s), Spring creates a proxy implementing same interface(s) wrapping the original class and weaves advices (typical decoration pattern). But for the case that original class doesn’t implement any interface(s), Spring creates a proxy inheriting it and weaves advices. Then you will see exception indicating ‘can’t extends final class’.

That’s where my question comes from. With AOP, does the practice marking a class final to be immutable become obsolete?

I didn’t use AspectJ properly so far, but I know it supports compile time weaving and load time weaving besides run time weaving. Also it supports more pointcut ways. Does my question apply to AspectJ or not, I am not quite sure. I think it really depends on how the special compiler and classloader weaves advices.

Any thoughts on this?

trends Use case Advice (programming) Spring Framework Weave (protocol) IT AspectJ Extent (file systems) Mark (designation)

Opinions expressed by DZone contributors are their own.

Popular on DZone

  • Understanding gRPC Concepts, Use Cases, and Best Practices
  • Distributed SQL: An Alternative to Database Sharding
  • The Future of Cloud Engineering Evolves
  • Using the PostgreSQL Pager With MariaDB Xpand

Comments

Partner Resources

X

ABOUT US

  • About DZone
  • Send feedback
  • Careers
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 600 Park Offices Drive
  • Suite 300
  • Durham, NC 27709
  • support@dzone.com
  • +1 (919) 678-0300

Let's be friends: