4 Replies Latest reply: Sep 17, 2010 1:38 PM by 843793 RSS

    Howto avoid specifying the type for every subclass?

    843793
      Hi,

      I have a base-class called DynTableColumn, one subclass which further restricts the type and a bunch of subclasses of that type.
      class BaseClass<E> {}
      
      StricterBaseClass<E extends ArgumentType> extends BaseClass<E> {}
      
      ConcreteClass1<E extends ArgumentType> extends StricterBaseClass<E> {}
      ConcreteClass2<E extends ArgumentType> extends StricterBaseClass<E> {}
      ConcreteClass3<E extends ArgumentType> extends StricterBaseClass<E> {}
      ConcreteClass4<E extends ArgumentType> extends StricterBaseClass<E> {}
      Is there any way to avoid specifying <E extends ArgumentType> for ConcreteClass 1-4 again and again?
      After all, the type information is already set by StricterBaseClass.

      Re-thinking the question I guess I am searching for a way to de-generify concrete subclasses.
      For the example above I know the generic type is of type ArgumentType, so no further need to specify it in the class hierachy nore at construction time.

      Thank you in advance, Clemens
        • 1. Re: Howto avoid specifying the type for every subclass?
          thomas.behr
          linuxhippy wrote:
          For the example above I know the generic type is of type ArgumentType, so no further need to specify it in the class hierachy nore at construction time.
          Ok, how about
          class BaseClass<E> {}
           
          StricterBaseClass extends BaseClass<ArgumentType> {}
           
          ConcreteClass1 extends StricterBaseClass {}
          ConcreteClass2 extends StricterBaseClass {}
          ConcreteClass3 extends StricterBaseClass {}
          ConcreteClass4 extends StricterBaseClass {}
          However, the desire to save a few characters in the class declaration doesn't have much merit - after all the small amount of characters in "<E extends ArgumentType>" is surely negligible with regards to the number of characters needed for actual implementations of class methods, isn't it?
          • 2. Re: Howto avoid specifying the type for every subclass?
            843793
            Excellent, thanks :)
            However, the desire to save a few characters in the class declaration doesn't have much merit - after all the small amount of characters in "<E extends
            ArgumentType>" is surely negligible with regards to the number of characters needed for actual implementations of class methods, isn't it?
            Sure the amount of characters is negligible, but I don't want the Concrete Classes to be generic anymore.

            Thanks again, Clemens
            • 3. Re: Howto avoid specifying the type for every subclass?
              796085
              Except that they're not the same thing...
              • 4. Re: Howto avoid specifying the type for every subclass?
                843793
                dannyyates wrote:
                Except that they're not the same thing...
                plus-plus.

                FWIW, if you're creating so many classes that you get annoyed by boilerplate in class definitions (not even usages) then perhaps you have an over- or poorly-engineered architecture.