0

I am supposed to design a re-usable component. It will be a Java library with a API interface, hiding all implementation details including internal data dependency. It requires a set of static data that a client application needs to configure in the library before calling any methods

After a lot of debate and discussions we have come up with two design approaches

  1. First design approach: static data is internal to library so, the implementation for quarrying and data look up tables should be implemented internally transparent to the client application of the library

    In this approach we'd do the following:

    a1. library internally depends on a abstract static data interface and there are various data source implementations: ex: database-query implementation, file query implementation, config query implementation
    a2. Client application configures an implementation with source of the static data

    Debates against this approach:

    d1. a library should not make database connection
    d3. a client is bound to the data schema as it can not change the queries. only it can point the libray to the data source

  2. In the second design approach: Static data is viewed as a dependency (even though it is internal to the library). so it should be injected, i.e. client application of the library needs to implement all static data look up

    We'd do the following:

    a. library implements a service provider interface (SPI)
    b. client applications need to implement the interface
    c. look up tables are with the client application

    Debates against this approach

    d1. Static data is internal to the library, a user of library should not worry about implementation
    d2. As data for different clients will be mostly same, there will be redundant code
    d3. more redundant code = more errors

I am not sure which approach to follow. If you can recall a elegant approach from your experience it will be really helpful to me.

many thanks in advance!

1 Answer 1

0

I'd suggest going with option 2 to keep your library modular for even your own maintenance purposes. To solve the issue of having the client implement the data connection logic by themselves, ship your library with the configuration files (such as Mapper XML for using MyBatis for DB connection) that the user can edit if they choose to update it.

You could provide other configuration options for using other data connections but they don't have to be as easy as just editing an XML file.

You could make going with the default the easiest option and require the user to put in more work as the farther away from the default his requirements go, all the while avoiding coding yourself into a corner.

3
  • thank you for the answer. Actually with option 2, a client has more flexibility of selecting an altogether new data query implementation.
    – Sanjit
    May 21, 2013 at 16:58
  • but at the same time, if there are 2 different clients using this library, they need to implement the same sort of look up.There is a overhead of exposing the query interface to be implemented by the client
    – Sanjit
    May 21, 2013 at 17:00
  • Sounds like your functionality needs to be more than just a library. An installation or setup should take care of setting up the various defaults/user preferences. May 21, 2013 at 18:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.