Gnanaprakash R’s Post

💡 1 Java Concept Every QA Should Know – #19: Abstraction (Abstract Class vs Interface 🔥) When I started designing frameworks, one confusion I had was: 👉 When to use abstract class? When to use interface? Understanding this made my framework much cleaner 👇 --- 🔹 What is Abstraction? Abstraction means: 👉 Hiding implementation and exposing only required actions --- 🔥 1. Abstract Class Example abstract class BasePage { abstract void openPage(); void commonAction() { System.out.println("Common steps"); } } class LoginPage extends BasePage { @Override void openPage() { System.out.println("Open Login Page"); } } ✔ Can have both abstract & non-abstract methods --- 🔥 2. Interface Example interface LoginActions { void login(); void logout(); } class LoginPage implements LoginActions { public void login() { System.out.println("Perform login"); } public void logout() { System.out.println("Perform logout"); } } ✔ Only method declarations (no implementation) --- 🔥 QA Use Case 👉 Abstract Class → Common reusable logic (BasePage) 👉 Interface → Define actions/contract (login, logout) --- 🎯 Key Difference ✔ Abstract class → “What + How (partial)” ✔ Interface → “What only” --- ❗ Common Mistakes ❌ Using abstract class everywhere ❌ Not using interface for flexibility ❌ Confusing both concepts --- 💡 Pro Tip 👉 Use interface for flexibility 👉 Use abstract class for shared logic --- 💡 My Learning Clean frameworks separate: 👉 What to do (interface) 👉 How it’s done (implementation) That’s the real power of abstraction 💪 --- 📌 Tomorrow → Real-time OOP Example in Automation (Putting it all together 🔥) Follow for more QA-focused Java concepts 👍 #Java #QA #AutomationTesting #SDET #SoftwareTesting #LearningJourney

To view or add a comment, sign in

Explore content categories