简体   繁体   中英

How to wrap similar classes from different packages

I develop an app for android which uses standard android.database.sqlite.SQLiteDatabase as well as net.sqlcipher.database.SQLiteDatabase .

These classes are very similar but I have to duplicate some pieces of code just to handle these different types, even if I need to call the same methods.

Can anybody advice what would be the best way to create some wrapper around these classes to have single interface for interaction with both types.

I would create an interface with all the methods that are shared plus any other you think necessary. Then write a factory class that will create either a AbsSQLiteDatabase from android or AbsCipherSQL (which would be private or package classes) and return it in the form of the interface.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM