Inheritance and Parcels

In Android development, we have Parcelable interface.
Since I wish to build Data Models that will run on multiple apps and services (not just Android), I would like to add two jar libs that will share some of the code across multiple implementations:
1. The first A is coupled with Android SDK
2. The second B is not coupled with Android SDK

The B package will contain Data Models (POCO objects), for example.
Since B has no reference to Android SDK, and I would like my POCO objects to implement Parcelable, then I think it would be nice to inherit from all POCO objects and implement the Parcel objects only in package A.

The same goes for methods and utilities that are only available in Android, and have other implementations in Java.

Is that the right approach for developing multiple apps and services that might share code?


So, it does seems to be the approach in the eyes of DevOps. Code sample:
This is a class from package B (as defined in the question):

public class APIResponseStatus implements Serializable {  
  protected String errorCode = null;
  protected String status = null;
  protected String message = null;

This is a class from package A (as defined in the question):

public class APIResponse extends APIResponseStatus implements Parcelable {  
  .... // including Parcelable implementation

This line of code works as expected:

APIResponse response = intent.getParcelableExtra("RESPONSE_OBJECT");

Trả lời

Email của bạn sẽ không được hiển thị công khai. Các trường bắt buộc được đánh dấu *