Interfaces
Definition 1:
A Service Requirement Specification (SRS) is considered an interface.
A Service Requirement Specification (SRS) is considered an interface.
Example 1: JDBC
The JDBC API specifies the requirements for developing a database driver. The database vendor is responsible for implementing the 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 the client expects.
From the service provider's point of view, an interface defines the set of services the provider offers.
Therefore, any contract between a client and a service provider can be considered an interface.
From the client's point of view, an interface defines the set of services the client expects.
From the service provider's point of view, an interface defines the set of services the provider offers.
Therefore, any contract between a client and a service provider can be considered an interface.
Example: ATM System
The bank's ATM GUI screen represents the services offered by the bank and accepted by the customer. Hence, it acts as a contract between the two.
Bank System
⇄
ATM Interface
⇄
Customer
Definition 3:
Traditionally, every method inside an interface is abstract by default. Hence, an interface is considered a 100% pure abstract class.
Traditionally, every method inside an interface 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 it.
An interface is a blueprint of a class that contains abstract methods and constants. It specifies what to do, but not how to do it.
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
- Constructors are not allowed
- Multiple inheritance is supported
Why Use Interfaces?
- 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 a Client & a Service Provider
✔ 100% Abstract Class
✔ Blueprint for classes
✔ Service Requirement Specification (SRS)
✔ Contract between a Client & a Service Provider
✔ 100% Abstract Class
✔ Blueprint for classes
0 Comments