Skip to main content

7 posts tagged with "interfaces"

View All Tags

Spring Data JPA Part 5: Why UserRepository MUST Be an Interface - Java Type System Rules

· 8 min read
Mahmut Salman
Software Developer

"Why can't I use class instead of interface for UserRepository?" Because Java's type system has strict rules: class extends class, interface extends interface, class implements interface. When you try class UserRepository extends JpaRepository, Java sees JpaRepository is an interface and throws an error. Let's understand the three-level inheritance chain and who implements what.

Utility Classes vs Interfaces: Why Static Methods Aren't Enough

· 8 min read
Mahmut Salman
Software Developer

"Can't we just create a utility class with static methods instead of using interfaces? Isn't the interface approach just fancy?" Great question! Yes, you could use utility classes - but you'd be solving only 50% of the problem. Let's see what happens in practice and why interfaces aren't fancy, they're necessary.