I am building a service for cleansing physical addresses. I have an API bundle that contains an interface with a cleanse method. This method would take in a list of raw address data. I would then have an implementation bundle that would implement the cleanse method and expose a service. Client bundles would then have a dependency on the API bundle and have a reference to the exposed service. I'm struggling with figuring out the "best" way to do it. I am thinking of two options:
Option 1:
The API bundle has a RawAddress value class. This means I have a concrete class in the API bundle, which I believe is frowned upon in the OSGI world, or at least is not a best practice (see Is separate OSGI bundles for api and implementation common practice? - especially Neil's comment on the accepted answer).
From the client perspective:
List<RawAddress> rawAddresses = new ArrayList<>();
for(...) {
RawAddress address = new RawAddress(addrLine, city, state, zip);
rawAddresses.add(address);
}
List<CleanAddress> cleanAddresses = addressService.cleanse(rawAddresses);
Option 2:
RawAddress is instead an interface in the API bundle. The AddressService object would have an additional method for creating objects that implement RawAddress. This leaves the API bundle "pure" but it also feels like it may be overkill.
From the client perspective:
List<RawAddress> rawAddresses = new ArrayList<>();
for(...) {
RawAddress address = addressService.newRawAddress(addrLine, city, state, zip);
rawAddresses.add(address);
}
List<CleanAddress> cleanAddresses = addressService.cleanse(rawAddresses);
I feel like I'm over-thinking this and/or that I'm missing some better solution. Any thoughts?