Professional Documents
Culture Documents
Bindings and Coupling in Java: Instructor
Bindings and Coupling in Java: Instructor
Bindings
Types of Bindings
Coupling
Types of Coupling
Binding in Java
3
Static binding (Early binding) is done during compile-time while dynamic binding
(Late binding) is done during run-time.
Private, final and static methods and variables uses static binding and bonded by
compiler while overridden methods are bonded during runtime based upon type of
runtime object.
Understanding Type (Let's understand the type of instance)
5
class Animal{
void eat() {System.out.println("animal is eating...");}
}
class Dog extends Animal
{
void eat() {System.out.println("dog is eating...");}
• Tight coupling
(It is when a group of classes are highly dependent on one another)
• Loose coupling
(When an object gets the object to be used from external sources, we call it
loose coupling)
Tight coupling (Example)
10
class Subject
{ Explanation: In this program the
Topic t = new Topic(); Subject class is dependents on Topic
public void startReading() class. In this program Subject class is
{ tightly coupled with Topic class it
t.understand(); means if any change in the Topic
} class requires Subject class to
} change. For example, if Topic class
class Topic understand() method change to
{ gotit() method then you have to
public void understand() change the startReading() method
{ will call gotit() method instead of
System.out.println("Tight coupling concept"); calling understand() method.
}
}
Loose coupling (Example)
11
•Tight coupling is not good at the test-ability. But loose coupling improves the test
ability.
•Tight coupling does not provide the concept of interface. But loose coupling helps us
follow the GOF (gang of four) principle of program to interfaces, not implementations.
•In Tight coupling, it is not easy to swap the codes between two classes. But it’s much
easier to swap other pieces of code/modules/objects/components in loose coupling.
•Tight coupling does not have the changing capability. But loose coupling is highly
changeable.
GOF / Gang of Four Design Patterns in Java. These are design patterns which were defined by four authors – Erich
Gamma, Richard Helm, Ralph Johnson and John Vlissides in their book Design Patterns: Elements of Reusable Object-
Oriented Software.
Differences b/w tight and loose coupling
13
References
14
THANK YOU