Multiple Inheritance under Android

Put your problem here if it does not fit any of the other categories.

Multiple Inheritance under Android

Postby Sepho » Thu Mar 24, 2011 4:37 pm

Hi guys,

We are developing adroid app who uses very similar code under 3 or more classes. We've been thinking about to create a super class with the similar code and then use Inheritance to get the code. The problem is that the Activities actually extends Activity class and Java does not support multiple Inheritance.


Any solution? The principal purpose is to reduce code lines under our classes.

Thanks!!
User avatar
Sepho
Freshman
Freshman
 
Posts: 9
Joined: Sat Dec 18, 2010 3:22 pm

Top

Re: Multiple Inheritance under Android

Postby raj_J2ME » Fri Mar 25, 2011 7:54 am

Hi there are two ways you can proceed with... :)

1. You put the entire code inside the one super class which extends from the Activity class. In turn all the other classes which wanna use that code can extends this Class and hence all the child classes will be Activity only. I wonder if there are any issues with this.

2. You can make one class as the abstract class and let the child classes extends the same as per the need,

AFAIK the first choice can serve your objective. I wonder if at the same time you need class which is multiple inheriting. You can also think of the Interface also.
Thanks with Regards,
Raj - The Kernel
raj_J2ME
Master Developer
Master Developer
 
Posts: 311
Joined: Tue Feb 15, 2011 7:40 am
Location: The Capital of India,

Re: Multiple Inheritance under Android

Postby Sepho » Fri Mar 25, 2011 9:16 am

raj_J2ME wrote:Hi there are two ways you can proceed with... :)

1. You put the entire code inside the one super class which extends from the Activity class. In turn all the other classes which wanna use that code can extends this Class and hence all the child classes will be Activity only. I wonder if there are any issues with this.

2. You can make one class as the abstract class and let the child classes extends the same as per the need,

AFAIK the first choice can serve your objective. I wonder if at the same time you need class which is multiple inheriting. You can also think of the Interface also.


Thanks raj_J2ME! First solution seems to be the best way to do it! :) The problem with interfaces is that all methods needs to be abstract method, so we don't reduce code.

Thanks!
User avatar
Sepho
Freshman
Freshman
 
Posts: 9
Joined: Sat Dec 18, 2010 3:22 pm

Re: Multiple Inheritance under Android

Postby raj_J2ME » Fri Mar 25, 2011 10:26 am

Yeah, making the class abstract or using the interfaces might cause the issues. So the first way to do this seems to be the good one. All the best.
Thanks with Regards,
Raj - The Kernel
raj_J2ME
Master Developer
Master Developer
 
Posts: 311
Joined: Tue Feb 15, 2011 7:40 am
Location: The Capital of India,

Top

Return to Other Coding-Problems

Who is online

Users browsing this forum: No registered users and 8 guests