Contents
What differences are there between superclasses and interfaces?
Remember, a Java class can only have 1 superclass, but it can implement multiple interfaces. Thus, if a class already has a different superclass, it can implement an interface, but it cannot extend another abstract class. Therefore interfaces are a more flexible mechanism for exposing a common interface.
What is the benefit of interfaces in java?
Why do we use interface ? It is used to achieve total abstraction. Since java does not support multiple inheritance in case of class, but by using interface it can achieve multiple inheritance . It is also used to achieve loose coupling.
How is loose coupling achieved using interfaces in Java?
That allows you to feed different classes to the same code without having to modify it. Please note that interfaces are not the only way to reach a loose coupling of components. Loose coupling just means that components are able to work together without assuming anything about the internal workings of each other.
How are interfaces used to decouple concrete classes?
A loosely-coupled class can be consumed and tested independently of other (concrete) classes. Interfaces are powerful tools used for decoupling. Classes can communicate, through interfaces, to other concrete classes, and any class can be on the other end of that communication simply by implementing the interface.
Why is loose coupling so important in microservice architecture?
In short, loose coupling in microservice architecture means microservices should know little about each other, and any change to one service should not affect the others. Why is loose coupling so important in microservice architecture?
What is the difference between loose coupling and tight coupling?
Loose Coupling is achieved by means of a design that promotes single-responsibility and separation of concerns. A loosely-coupled class can be consumed and tested independently of other (concrete) classes. Interfaces are powerful tools used for decoupling.