
INTERFACES VS. ABSTRACT CLASSES: A REAL-WORLD JAVA EXAMPLE
If you’re familiar with OOP (Object Oriented Programming), you’ll probably recognise the following code: an Animal class, a Dog class, and a method called bark. It’s good code if you want to learn Java syntax. It’s bad code if you want to understand software architecture. Nobody in the real world writes code to make digital dogs bark. If you only learn these abstract metaphors, you’ll never understand why we use polymorphism or why an interface might be a good idea. Today, we’ll skip the zoo. We’ll write a real-world e-commerce checkout application using Java and show how using an interface helps your application scale without changing your core code. The problem: the tightly coupled nightmare Let’s say you’re building a checkout application. At first, your boss says: “Hey, we only accept Credit Cards.” So you write a service class called CheckoutService that calls a CreditCardAPI . A month passes. Your boss says: “Hey, we need to accept PayPal.” Then: “Hey, we need to accept Crypto.”
Continue reading on Dev.to
Opens in a new tab

