question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

FEATURE REQUEST:Multi Level Multiple Inheritance and Override Support

See original GitHub issue

WIP still working on the issue and its associated PR, please bear with me

Goals

Multi Level (Generic) Inheritance With Multiple Inheritance Support at the Second (and Higher) Level And Generic Method Override

Here, the feign client interface SomeServiceClientApi inherits from the interface SomeService, which then inherits from multiple other (generic) interfaces, sharing its interface with the SomeServiceApiController rest controller via the SomeService interface.

interface RetrieveService<T> {
  T retrieve(String key);
}

interface StatusService {
  String status();
}

interface SomeService extends RetrieveService<String>, StatusService {
}

@FeignClient
interface SomeServiceClientApi extends SomeService {
   @GetMapping("/retrieve/{key}", produces="text/plain")
   @Override
   String retrieve(@PathVariable("key") String key);

   @GetMapping("/status", produces="text/plain")
   @Override
   String status();
}

@RestController
class SomeServiceApiController implements SomeService {

  @GetMapping("/retrieve/{key}", produces="text/plain")
  @Override
  @ResponseBody
  public String retrieve(@PathVariable("key") String key) { ... }

  @GetMapping("/status", produces="text/plain")
  @Override
  @ResponseBody
  String status() { ... }
}

or, alternatively (and most provably in combination with the above)

interface RetrieveService<T> {
  T retrieve(String key);
}

interface StatusService {
  String status();
}

interface SomeService extends RetrieveService<String>, StatusService {
}

interface SomeServiceApiBase extends SomeService {
   @GetMapping("/retrieve/{key}", produces="text/plain")
   @ResponseBody
   @Override
   String retrieve(@PathVariable("key") String key);

   @GetMapping("/status", produces="text/plain")
   @ResponseBody
   @Override
   String status();
}

@FeignClient
interface SomeServiceClientApi extends SomeServiceApiBase {
}

@RestController
class SomeServiceApiController implements SomeServiceApiBase {

  @Override
  // going for the naive Spring will fixit approach here, alternatively one must repeat the `@PathVariable` annotation
  // on the formal method parameter here
  public String retrieve(String key) { ...; }

  @Override
  public String status() { ...; }
}

Decomposition of the Service Interface for both Testing and Delegation Purposes

A so composed service interface can be decomposed so that one can test indiividual features of a service a/o client using shared (generic) test classes a/o strategies, when considering standard CRUD and other operations.

One could also use delegates on the server side to realize specific facets of the service interface, e.g. one that will realize the status and one that will realize the retrieve, and so on.

And while the Spring framework already provides for such, Feign will currently prevent this from happening as it does not support multiple inheritance on the interface level. Basically meaning that one cannot have a service interface that is shared between both the client and the server without having to redeclare the client interface.

Positive Side Effects

  • overriding methods from (parameterized) base interfaces is now supported

Implementation Notes

Since spring-cloud-openfeign does override some of the process* methods from Contract.BaseContract, I resorted to just detecting when multiple methods with the same key are available.

Annotations on base interfaces, except for when it is the first inherited one, are simply ignored.

Additional test cases have been introduced that provide for a basic safeguard but do not realize every possible combination.

Additional Information

spring-cloud-openfeign must be updated so as to use the new version.

PR

#1285

See also

#320, #1244, #1029

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:5
  • Comments:11 (11 by maintainers)

github_iconTop GitHub Comments

1reaction
silkentrancecommented, Oct 26, 2020

The current PR #1285 incorporates changes that will make it most versatile, reducing overall complexity and all. Feel free to test this out, see https://github.com/OpenFeign/feign/issues/1284#issuecomment-716050174

A new snapshot release has been made available.

1reaction
silkentrancecommented, Oct 18, 2020

@kdavisk6 Hi, I wanted to know whether you are still interested in multiple inheritance support? Maybe you can drop a comment or two on the PR and the way that this was realized. TIA!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Multiple Inheritance in Java | DigitalOcean
Unlike some other popular object oriented programming languages like C++, java doesn't provide support for multiple inheritance in classes.
Read more >
Multiple inheritance in C++ leading to difficulty overriding ...
If the two inherited functions had different signatures, there would be no problem: We would just override them independently as usual. The ...
Read more >
Java and Multiple Inheritance - GeeksforGeeks
Multiple Inheritance is a feature of an object-oriented concept, where a class can inherit properties of more than one parent class.
Read more >
Python Multiple Inheritance (with Examples) - TechBeamers
This tutorial describes the Python Multiple Inheritance concept, explain multilevel inheritance, and super() function with the help of examples.
Read more >
Method overriding in multiple inheritance - YouTube
In this tutorial we will learn about method overriding in multiple inheritance. in multiple inheritance a class can be derived from multiple ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found