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
Please enter at least three characters to search
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

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

Because the DevOps movement has redefined engineering responsibilities, SREs now have to become stewards of observability strategy.

Apache Cassandra combines the benefits of major NoSQL databases to support data management needs not covered by traditional RDBMS vendors.

The software you build is only as secure as the code that powers it. Learn how malicious code creeps into your software supply chain.

Generative AI has transformed nearly every industry. How can you leverage GenAI to improve your productivity and efficiency?

Related

  • SaaS in an Enterprise - An Implementation Roadmap
  • AI-Driven RAG Systems: Practical Implementation With LangChain
  • Injecting Implementations With Jakarta CDI Using Polymorphism
  • STRIDE: A Guide to Threat Modeling and Secure Implementation

Trending

  • Intro to RAG: Foundations of Retrieval Augmented Generation, Part 1
  • Operational Principles, Architecture, Benefits, and Limitations of Artificial Intelligence Large Language Models
  • Endpoint Security Controls: Designing a Secure Endpoint Architecture, Part 2
  • Building a Real-Time Change Data Capture Pipeline With Debezium, Kafka, and PostgreSQL

Implementation Independence

The Gang of Four taught us to design to interfaces, not to implementations.

By 
David Bernstein user avatar
David Bernstein
DZone Core CORE ·
Updated Sep. 12, 16 · Opinion
Likes (5)
Comment
Save
Tweet
Share
5.9K Views

Join the DZone community and get the full member experience.

Join For Free

“Design to interfaces, not implementations.” This is the advice that the Gang of Four gave us in their book, Design Patterns: Elements of Reusable Object Oriented Software. This means to hide implementation details and only present what is to be accomplished by crafting method signatures around testable behaviors. It means using APIs to create clear contracts for services while hiding as much as possible about how those services do their work. Much of the job of a good programmer is to find ways of encapsulating as much as possible while still creating the desired behavior.

I like to think of myself as an enlightened human being. I believe in equality not just for all humans but for all living things. But I don’t share that same attitude in my software. With people, I want to share as much as I can, but with my objects I want to hide as much of the world as possible from them. All of my software is on a nee-to-know basis. While that may sound a bit harsh at first, it stops my code from being pinned down by many implementation details and allows me to easily refactor and extend it with little friction.

I don’t want to give you the impression that I am cruel to my objects, nothing is further from the truth. I’m actually quite kind to them. I never overburden them with more than one responsibility, and I always keep them testable, so I’m constantly checking in with them and making sure they still work as expected. This reassures my code, and me, as well as my customers.

Implementation details can sometimes leak into our designs without us even being aware of it.

For example, I follow a practice called encapsulation of construction when I build my objects. I give each object the ability to create itself by adding a public static method that “news” itself up. I usually call this method getInstance(). I once worked with a client who was looking my code and asked me why I create so many Singletons in my code. I told him I try to avoid creating Singletons in my code and he pointed out all the “getInstance()” methods.

Why did he think I was creating Singletons in my code?

It turns out in the Gang of Four’s example of a Singleton in their book, they use the method name getInstance() but that doesn’t mean when you see the name getInstance() you should think of a Singleton. That’s an implementation detail. From the caller’s perspective, they’re simply asking for an instance. It shouldn’t matter whether you get a unique instance or you get access to some global resource through a Singleton. Perhaps a single resource becomes a bottleneck in the system and it needs to be refactored to a doubleton or a tripleton—or even an object pool. Would you ask all of your clients to rename the method they used from getInstance() to something else?

Hiding implementation details makes code more straightforward to test and understand.

The fewer assumptions we make in code, the less implementation details we expose and the more freedom we have to change our code in the future without impacting our callers. This dramatically drops the cost of ownership for the software we write. Given that over 80% of the cost of software happens after the initial release, writing code that is less expensive to maintain and extend is critically important.

Implementation

Published at DZone with permission of David Bernstein, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

Related

  • SaaS in an Enterprise - An Implementation Roadmap
  • AI-Driven RAG Systems: Practical Implementation With LangChain
  • Injecting Implementations With Jakarta CDI Using Polymorphism
  • STRIDE: A Guide to Threat Modeling and Secure Implementation

Partner Resources

×

Comments
Oops! Something Went Wrong

The likes didn't load as expected. Please refresh the page and try again.

ABOUT US

  • About DZone
  • Support and feedback
  • Community research
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

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

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 100
  • Nashville, TN 37211
  • support@dzone.com

Let's be friends:

Likes
There are no likes...yet! 👀
Be the first to like this post!
It looks like you're not logged in.
Sign in to see who liked this post!