Question: I have an app ready and running in the Google Play store, now i am implementing fragments.

so,i already have a class A which extends B with some methods, now i have class which C extends FragmentActivity, so now i need use the same methods as in class A but here since i am extending FragmentActivity i cannot make use of class B, so here there are duplicate methods which are same as class A but i need to reuse the methods.

This below example shows my situation:

Eg:

**Current implementation**

```
class A extends B{

one();
two();

}

```

**After integrating fragments,**

Eg:

```
class C extends FragmentActivity{

one();// same methods as in class A
two();// same methods as in class A

}

```

1) What is the best way to re-use the methods in this case and how?

2) I have approach in my mind like creating a class and make the methods as static and re-use the methods in both A and C class, but is my approach good and can i make the methods as static and is it a good approach ?

3) Another approach that i have thought of **"Strategy Pattern".**

```
Eg:
class A extends ApiClass {
   private ClassContainingDupMethod strategy;
}

class N extends AnotherApiClass {
   private ClassContainingDupMethod strategy;

   public methodCallingDupMethod(){
      strategy.dupMethod();
   }
}

class ClassContainingDupMethod{
   public dupMethod(){;}
}

```

Is the **"Strategy Pattern".** a good approach ? as i need to create object of common class in both the classes.

Any suggestions on this would be appreciated.

Answer: 
Get rid of inheritance as much as you can. You don't need it. Class inheritance is almost always a bad idea, especially if you expect lots of future changes in your implementation. The only time it is really necessary is when a poorly designed framework requires you to extend some base class. 

When reading the old design patterns from Gamma et al., bear in mind that they were written for a world where C++ and Pascal were the dominant OO languages. Java was still in its infancy and introduced a novelty (interfaces) that neither of those languages had. So, you should mentally replace a lot of the uses of extends with implements and you'll end up with better code.

Basically, keeping coherence high, and coupling low is a good idea in object oriented design. Class inheritance can easily lead to highly coupled classes with low coherence (lots of unrelated functionality in one class). The reason is that the base class ends up having functionality that is not needed by all sub classes, or code paths that are only relevant for some. Additionally, as your design evolves, you end with lots of classes that inherit from each other and are very tightly coupled. I personally hate having to deal with code with multiple levels of inheritance. It's hard to read and the semantics of inheritance make testing more painful as well. I never use extends other than for interfaces and I've been doing Java since the mid nineties.

@Babibu's suggestion of using composition and delegation is a much better alternative for this reason. It leads to more coherent classes that are much less tightly coupled. Easier to maintain, easier to recompose, easier to test, etc.
If you've got same methods in both fragments, why don't you use a BaseFragment class (which in turn extends FragmentActivity) and have all your common methods there. Then you can just extend this BaseFragment class in any class you wish to.
This way, whatever methods you've got in BaseFragment can be just utilized without re-defining.