[jira] [Commented] (IGNITE-10441) Fluent API refactoring.
[ https://issues.apache.org/jira/browse/IGNITE-10441?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=16897038#comment-16897038 ] Aleksey Zinoviev commented on IGNITE-10441: --- Great thing after year of using. [~amalykh] could you share more wisdom about this approach (paper, book, link?) > Fluent API refactoring. > --- > > Key: IGNITE-10441 > URL: https://issues.apache.org/jira/browse/IGNITE-10441 > Project: Ignite > Issue Type: Improvement > Components: ml >Reporter: Artem Malykh >Assignee: Artem Malykh >Priority: Major > > 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: > > {code:java} > class A> { > Self withX(X x) { > this.x = x; > > return (Self)this; > } > class B> extends A { >// No need to override "withX" here >Self withY(Y y) { > this.y = y; > > return(Self)this; >} > } > class C> extends B { >// No need to override "withX" and "withY" methods here. > } > //... etc > {code} -- This message was sent by Atlassian JIRA (v7.6.14#76016)
[jira] [Commented] (IGNITE-10441) Fluent API refactoring.
[ https://issues.apache.org/jira/browse/IGNITE-10441?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=16701983#comment-16701983 ] Aleksey Zinoviev commented on IGNITE-10441: --- Let's discuss it on the dev-list > Fluent API refactoring. > --- > > Key: IGNITE-10441 > URL: https://issues.apache.org/jira/browse/IGNITE-10441 > Project: Ignite > Issue Type: Improvement > Components: ml >Reporter: Artem Malykh >Assignee: Artem Malykh >Priority: Major > > 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: > > {code:java} > class A> { > Self withX(X x) { > this.x = x; > > return (Self)this; > } > class B> extends A { >// No need to override "withX" here >Self withY(Y y) { > this.y = y; > > return(Self)this; >} > } > class C> extends B { >// No need to override "withX" and "withY" methods here. > } > //... etc > {code} -- This message was sent by Atlassian JIRA (v7.6.3#76005)