How to Make an efficient connection between two interfaces (Using generics)?
<p>first of all excuse me if this is a duplicate question.</p>

<p>I am writing a calculator for unlimited numbers.
since this is for unlimited number, i've decided to use a linked-list structure to store my numbers.</p>

<p>I wrote two interfaces: <code>Numbers</code> which stores numbers and <code>basicOperations</code> which is for operations.</p>

<p>i have two class: <code>Complex</code>  and  <code>Non_complex</code>, which implement Numbers.</p>

<p>the easiest way to connect <code>Numbers</code> and <code>basicOperations</code> is to implement <code>basicOperations</code> by <code>Complex</code> and <code>Non_Complex</code> and create instances and do the calculation, something like this:</p>

<pre><code>interface basicOperations {

    String addition(Numbers anotherNumber);
    // other methods
}


interface Numbers {
    //some methods
}


public class Complex implements Numbers, basicOperations {

    /**
     * some codes . . .
     */

    String addition(Numbers anotherNumber) {
        Complex secondNumber = (Complex) anotherNumber;
        /**
         * do the calculation and return the result
         */
    }
}
</code></pre>

<p>the same will be for <code>Non_complex</code>.</p>

<p>and finally i will use a switch-case, specify the operation from input, create 2 instances of <code>Complex</code> or <code>Non_complex</code> and store entered numbers in them, and do the calculation.</p>

<p>somehow, i don't want to use this way. i wanna challenge myself more with more complicated (Better) ways. i've thought about some ways, one of them is this:</p>

<p>creating a class (assume its name is <code>connect</code>) and do the operations in it like this:</p>

<pre><code>class connect {

    char currentOperation;

    void calculate(Numbers A, Numbers B) {
        if (currentOperation == '+') {
            addition.DoIt(A, B);
        }

        class addition implements calculate {

            static void &lt;U extends Complex&gt; DoIt(U num1, U num2) {
                System.out.println(num1.addition(num2));
            }

            static void &lt;U extends non_Complex&gt; DoIt(U num1, U num2) {
                System.out.println(num1.addition(num2));
            }

            static void &lt;U extends Numbers&gt; DoIt(U num1, U num2) {
                if (num1 instanceof Complex) {
                    Complex A = (Complex) num1;
                    Complex B = (Complex) num2;
                    System.out.println(A.addition(B));
                } else {
                    // the same codes like `if` will go for `Non-complex`.
                }
            }
        }
    }


interface calculate {

        static void &lt;U extends Numbers&gt; DoIt(U num1, U num2);
        static void &lt;U extends Complex&gt; DoIt(U num1, U num2);
        static void &lt;U extends Non_complex&gt; DoIt(U num1, U num2);


}
</code></pre>

<p>The other ways are similar like this way (using generics and connect two interfaces in a class and so on).</p>

<p>I'm new to generics and it's my first time to use multiple interfaces. i know there's a lot of ways, i'm looking for bests according to my program.</p>

<p>now, due to the question title, which way is more efficient, more optimized and better in every aspect?</p>

<p>and is my use of generics correct or i have to write it in another way?</p>

<p>Thanks a lot.</p>