1

There is a great Android library that I would like to reuse for a desktop application.

The only Android-specific part in this library is the use of android.database.sqlite.

What is the best practice in such cases?

  • Replace all calls to use a portable pure-Java SQLite package like SQLJet instead?
  • Wrap some SQLite Java library in a android.database.sqlite and use the library without any modification?
  • Any other clever solution?
Community
  • 1
  • 1
Nicolas Raoul
  • 58,567
  • 58
  • 222
  • 373

1 Answers1

1

First, This may be an overkill for your application.

My suggestion is to abstract the database calls to an interface. So for all pieces of your library that requires SQLite, use the new interface, and implement a 'SQLite Database Provider' that 'extends' the interface, which calls the SQLite methods.

What I'm suggesting is to use 'Dependency Injection' to inject the database parts to your library.

So when you're using the library in a desktop app, you can simply inject a different implementation of the interface (MySql Provider ?) and and you're ready to go.

This will also allow you to inject any other database providers at any time you like, without changing the core library code again.

Madushan
  • 6,977
  • 31
  • 79
  • You can also use Repository pattern for this, but you'll have to inject the repository at your startup phase too. – Madushan Aug 23 '12 at 02:00