4.2. Same Service Interface, Different Implementations

An advantage of separation of interface and implementation is that you can provide different implementations to the same interface. Let's see how we can provide another implementation of the DictionaryService interface in our dictionary bundle.

The following implementation class returns word definitions from Webster's dictionary:

 package com.acme.impl.dictionary; import java.util.*; import com.acme.service.dictionary.DictionaryService; class Webster implements DictionaryService { private Properties defs; Webster() { defs = new Properties(); defs.put("accuse", "to charge with a fault or offense"); defs.put("admire", "to marvel at or esteem highly"); defs.put("calamity", "a state of deep distress ...

Get Programming Open Service Gateways with Java Embedded Server™ Technology now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.