Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Differents kind of classes inherit from an abstract class in android java

Tags:

java

oop

android

I have two classes (ClassA and ClassB) that should be ListFragment. These two classes share behavior,thus I created an abstract class(AbstractClass). So AbstractClass inherit from ListFragment. So far I have my ClassA and ClassB that inherit from my AbstractClass which inherit from ListFragment. The problem comes when I need another ClassC that should be a Fragment(not ListFragment) but also it need the behavior from the AbstractClass, but I cant inherit from it because ClassC should be just Fragment and my abstractClass is ListFragment. I would like to have my ClassA,ClassB and ClassC inherit from my AbstractClass but being ClassA,ClassB Listfragment and ClassC just Fragment. Im sure should be some design pattern in Java or good practice to solve this.

I know that java does not allow multiple inheritance.

Many thanks

like image 979
FOMDeveloper Avatar asked Jan 20 '26 04:01

FOMDeveloper


1 Answers

Can you extract common functionality to some helper class? Use composition instead of inheritance

like image 74
Dmitry Avatar answered Jan 22 '26 17:01

Dmitry



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!