- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
What is loose coupling how do we achieve it using Java?
Coupling refers to the dependency of one object type on another, if two objects are completely independent of each other and the changes done in one doesn’t affect the other both are said to be loosely coupled.
You can achieve loose coupling in Java using interfaces -
Example
interface Animal { void child(); } class Cat implements Animal { public void child() { System.out.println("kitten"); } } class Dog implements Animal { public void child() { System.out.println("puppy"); } } public class LooseCoupling { public static void main(String args[]) { Animal obj = new Cat(); obj.child(); } }
Output
kitten
Advertisements