I would like to create some model classes that implement Android's Parcelable interface, but I want the classes to be usable outside Android. I thought about implementing a wrapper for all these model classes (they are serialized in the same way, with Google Protocol Buffers internally), but I am not sure how to do it.
Say I have an interface Model, and an implementing class ModelImpl. Currently, Model extends Parcelable, but I would like to decouple Model and ModelImpl from Parcelable, and have a ParcelWrapper instead. Preferably, this should all be type safe and nice. Any pointers as to how to approach this problem?
If I come across a solution, I'll post it here, of course.
Thanks! :)
I ended up using the decorator pattern. So now I've got:
Model and ModelImpl can now reside in their own library, and be used outside Android.
Unfortunately, I needed to write a decorator for each of my model classes, but this is the best solution I found until now. If I find something better, I will post it here.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With