I’m creating a custom Layout for android.
The layout implementation is exactly the same, but once I need to extend from RelativeLayout, and once from LinearLayout.
class Layout1 extends LinearLayout {
// methods and fields
}
class Layout2 extends RelativeLayout {
// the same EXACT methods and fields
}
How can I use inheritance to avoid code duplication and implement my methods once.
I do not know if it will fit your use case, but you might consider using delegation by adding a field of the “other” class.
I am pessimistic though as tha classes are too closely related.