Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Save more on your purchases now! discount-offer-chevron-icon
Savings automatically calculated. No voucher code required.
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Clojure Polymorphism

You're reading from   Clojure Polymorphism Leverage Clojure's polymorphic tools to develop your applications

Arrow left icon
Product type Paperback
Published in Nov 2019
Publisher
ISBN-13 9781838982362
Length 56 pages
Edition 1st Edition
Languages
Arrow right icon
Author (1):
Arrow left icon
Paul Stadig Paul Stadig
Author Profile Icon Paul Stadig
Paul Stadig
Arrow right icon
View More author details
Toc

Service Abstraction

Polymorphism is primarily used to create an abstraction that can be implemented in several ways. An abstraction that I have created many times is a service abstraction. For instance, you may want to define a storage service abstraction modeled as a key-value store for binary objects. You could then implement it for S3, CloudFiles, and Azure. For use in tests, you could even implement a local filesystem backend.

My abstraction will consist of five functions: connect, get, put, delete, and close. You call connect to construct a service object. The service object will be used with get to fetch an object from the store, put to store an object in the store, delete to delete an object from the store, and close to clean up the service object.

There are a couple of different ways of defining and implementing this abstraction. Each will have its own advantages and disadvantages. Let's first take a look at them, and then I will pick them apart for some design principles...

lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $19.99/month. Cancel anytime