Factory Method和Singleton你试一试.
package...public interfact Msg {
  // your msg interface
}package ...
public class MsgFactory {
    private static MsgFactory  instance = new MsgFactory();
    
    private MsgFactory() {
    }
    
    public static MsgFactoyr getInstance() {
       return instance;
    }
    
    public Msg createMsg(String type) {
       if (("type1").equals(type)) {
          return Type1Msg();
       }
       
       if (("type2").equals(type)) {
          return Type2Msg();
       }
       ...
       if (("type30").equals(type)) {
          return Type30Msg();
       } 
    }
}package ...public Type1Msg implements Msg {
        // your msg codes      
}package ...
public Type2Msg implements Msg {
        // your msg codes
}
...
package ...
public Tupe30Msg implements Msg {
       // your msg  codes
}