Interfaces
Definition 1:
Any service requirement specification (SRS) is considered an interface.
Any service requirement specification (SRS) is considered an interface.
Example 1: JDBC
A JDBC API specifies the requirements needed to develop a database driver. The database vendor is responsible for implementing this JDBC API.
JDBC API
(Interface)
(Interface)
➡
Database Vendor
(Implements)
(Implements)
Example 2: Servlet
The Servlet API defines the requirements for developing a web server. The web server vendor is responsible for implementing the Servlet API.
Servlet API
(Interface)
(Interface)
➡
Web Server
(Implements)
(Implements)
Definition 2:
From the client's point of view, an interface defines the set of services they expect.
From the service provider's point of view, an interface defines the set of services they offer.
Therefore, any contract between a client and service provider can be considered an interface.
From the client's point of view, an interface defines the set of services they expect.
From the service provider's point of view, an interface defines the set of services they offer.
Therefore, any contract between a client and service provider can be considered an interface.
Example: ATM System
The bank ATM GUI screen represents the services offered by the bank and accepted by the customer. Hence, it acts as a contract between both.
Bank System
⇄
ATM Interface
⇄
Customer
Definition 3:
Inside an interface, every method is abstract by default. Hence, an interface is considered a 100% pure abstract class.
Inside an interface, every method is abstract by default. Hence, an interface is considered a 100% pure abstract class.
Definition 4:
An interface is a blueprint of a class that contains abstract methods and constants. It specifies what to do but not how to do.
An interface is a blueprint of a class that contains abstract methods and constants. It specifies what to do but not how to do.
Definition 5:
Interfaces support multiple inheritance in Java. A class can implement multiple interfaces at the same time.
Interfaces support multiple inheritance in Java. A class can implement multiple interfaces at the same time.
Definition 6:
Interfaces provide 100% abstraction and help achieve loose coupling between components.
Interfaces provide 100% abstraction and help achieve loose coupling between components.
Key Features
- All methods are public and abstract (by default)
- Variables are public, static, and final
- No constructor is allowed
- Supports multiple inheritance
Why Use Interface?
- To achieve abstraction
- To support multiple inheritance
- To define standard rules for implementation
- To improve code flexibility and maintainability
Summary:
✔ Service Requirement Specification (SRS)
✔ Contract between Client & Provider
✔ 100% Abstract Class
✔ Blueprint for classes
✔ Service Requirement Specification (SRS)
✔ Contract between Client & Provider
✔ 100% Abstract Class
✔ Blueprint for classes
0 Comments
Hello