One idea
Polymorphism means your code can call the same method on different objects, and each object does the work in its own way.
An interface is a small contract for that method. Your main feature talks to the contract, not to one exact class.
Why it helps
In a real app, choices change. A canteen app may collect payment by UPI today, wallet tomorrow, and cash at the counter during a college fest.
If your order code directly depends on UPI code, every new payment type will force you to edit order code. Interfaces stop that spread.
When to use it
Do each one yourself, then tap it to tick it off. The ticks are only a checklist for you: they are not marked or scored.
0 of 5 done
Payment example
Here is a small Java example. The OrderService does not know whether payment is UPI or cash. It only knows that payment can be paid.
This makes the feature easy to extend and easy to test.
interface PaymentMethod {
boolean pay(int amountInRupees);
}
class UpiPayment implements PaymentMethod {
private final String upiId;
UpiPayment(String upiId) {
this.upiId = upiId;
}
public boolean pay(int amountInRupees) {
System.out.println("Collecting Rs " + amountInRupees + " using UPI: " + upiId);
return true;
}
}
class CashPayment implements PaymentMethod {
public boolean pay(int amountInRupees) {
System.out.println("Collect Rs " + amountInRupees + " at counter");
return true;
}
}
class OrderService {
private final PaymentMethod paymentMethod;
OrderService(PaymentMethod paymentMethod) {
this.paymentMethod = paymentMethod;
}
void placeOrder(int amountInRupees) {
boolean paid = paymentMethod.pay(amountInRupees);
if (paid) {
System.out.println("Order placed");
}
}
}
public class Main {
public static void main(String[] args) {
PaymentMethod payment = new UpiPayment("student@upi");
OrderService orderService = new OrderService(payment);
orderService.placeOrder(120);
}
}Use AI carefully
Ask an AI tool to suggest interfaces only after you describe the feature in plain words. Example: “In my canteen app, orders can be paid by UPI or cash. Suggest a small interface and classes in Java.”
Check that the AI does not create huge interfaces with many unrelated methods. A good interface is narrow. One job is enough.
Common mistake
Do not create an interface for every class. That only adds files without making the feature easier to change.
Use an interface when your feature has real variation, or when you need to swap a dependency in tests. If there is only one stable class, a class is fine.
Show it in your repo
For your HackIndia project, make the interface visible in your object model. A recruiter should be able to open your code and see the contract, the implementations, and the feature class that uses the contract.
In your README, write one short line like: “OrderService depends on PaymentMethod, so we can add new payment types without changing order placement logic.”
Do this now
Do each one yourself, then tap it to tick it off. The ticks are only a checklist for you: they are not marked or scored.
0 of 5 done