title: Design a Java interface: a method with variable numbers of parameters
body: <p>I just came into a problem with designing an interface whose methods may have variable numbers of input arguments. </p>
  
  <pre><code>public interface FoobarSerialization&lt;T&gt; {
      Foobar serialize(T obj); 
  }
  </code></pre>
  
  <p>The problem is, for the classes that implement this interface, they require different numbers of input arguments.</p>
  
  <pre><code>public class FoobarA implements FoobarSerialization&lt;FoobarA&gt; {
      @Override
      public Foobar serialize(FoobarA obj, int bar) {
          //...
      }
  }
  
  
  public class FoobarB implements FoobarSerialization&lt;FoobarB&gt; {
      @Override
      public Foobar serialize(FoobarB obj, Date date, String str) {
          //...
      }
  }
  </code></pre>
  
  <p>Is there a good design or any genuine way to solve this problem? I know the method in the interface can be declared as:</p>
  
  <pre><code>Foobar serialize(T... obj); 
  </code></pre>
  
  <p>But I'm not sure if this was a good practice to design an interface like this.</p>
  
  <p>Any thought?</p>
  
  <p><strong>Update</strong>: My intention of using an interface came from the collection of classes that need to be serialized and deserialized for different purposes. They serve as components under the same domain. But their serialization methods are quite different, especially considering their dependencies on objects and services that don't share any common features nor classes.</p>
  
  <p>I guess the right question to ask here is: in terms of design, what's the best approach when there exits a set of classes which share the same behaviors (serialize, deserialize, doSomething, etc) but have different input args?</p>