Uploaded image for project: 'Ignite'
  1. Ignite
  2. IGNITE-10441

Fluent API refactoring.

    XMLWordPrintableJSON

Details

    • Improvement
    • Status: Open
    • Major
    • Resolution: Unresolved
    • None
    • None
    • ml
    • None
    • Docs Required

    Description

      In many classes we have fluent API ("with*" methods). We have following problem: these methods should return exactly instance of it's own class (otherwise we'll have problems with subclasses, more precisely, if with method is declared in class A and we have class B extending A, with method (if we do not override it) will return A). Currently we opted to override "with" methods in subclasses. There is one solution which is probably more elegant, but involves relatively complex generics construction which reduces readability:

       

      class A<Self extends A<? super Self>> {
        Self withX(X x) {
          this.x = x;
           
          return (Self)this;
        }
      
      class B<Self extends B<? super Self>> extends A<B> {
         // No need to override "withX" here
         Self withY(Y y) {
           this.y = y;
           
           return(Self)this;
         }
      
      }
      
      class C<Self extends C<? super Self>> extends B<C> {
         // No need to override "withX" and "withY" methods here.
      }
      
      //... etc
      

      Attachments

        Activity

          People

            zaleslaw Alexey Zinoviev
            zaleslaw Alexey Zinoviev
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated: