简体   繁体   中英

Pattern for different implementations with certain restrictions

I'm coding a library that simplifies the use of Http request in Android and I've coded two different implementations (one using Apache libs, the other one using HttpUrlConnection) with a common interface.

I could leave it that way but I'm looking for a pattern that could represent better the following behaviour/limitations:
1. Implementation classes are singleton.
2. The library should be intended for making use of only one implementation in each program.
3. It must be easy to change between implementations.

I've already figured out how to do it without a design pattern, but I prefer to make the library the most "standard" it can be.

Maybe you should look at the Strategy pattern .

When designing a library it might also be better when you try to stay away from singletons (see Whats so bad about singletons?

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