Open kchaitanya-training opened 9 months ago
class Main{ public void mainMethod() { System.out.println("this is loose coupling"); I i = new MySqlB(); I j = new OracleA(); i.connection(); j.connection(); } } interface I{ void connection();
} class OracleA implements I{ public void connection() { System.out.println(" This is oracle calling."); } } class MySqlB implements I { public void connection() { System.out.println("This is mysql calling"); } } public class LooseTest {
public static void main(String[] args) {
Main m = new Main();
m.mainMethod();
//Output // Tight Coupling // I am M.
}
}
class M{ void methodM() { System.out.println("I am M."); } } class N{ void methodN() { System.out.println("Tight Coupling"); M m = new M(); m.methodM(); } }
public class TightTest { public static void main(String[] args) {
N n = new N();
n.methodN();
}}
public class Sport { public static void main(String[] args) {
Basketball bb = new Basketball();
bb.shooting();
bb.dribbling();
bb.blocking();
Football fb = new Football();
fb.shooting();
fb.dribbling();
}
}
public class Basketball implements shoot{ public void shooting() { System.out.println("Player shoots the ball"); } public void dribbling() { System.out.println("Player dribbles the ball"); } public void blocking() { System.out.println("Player blocks the ball"); }
}
public class Football { public void shooting() { System.out.println("Player shoots the ball"); } public void dribbling() { System.out.println("Player dribbles the ball"); }
}
public interface block { public void blocking();
}
public interface dribble { public void dirbbling();
}
public interface dribble { public void dirbbling();
}
output Player shoots the ball Player dribbles the ball Player blocks the ball Player shoots the ball Player dribbles the ball
package CarBrands;
//loose coupling
public interface Car {
void features();
public static void main(String[] args) {
Bmw newBmw = new Bmw();
newBmw.features();
Audi newAudi = new Audi();
newAudi.features();
}
}
package CarBrands;
class Audi implements Car {
@Override public void features() { System.out.println("It is luxurious."); }
}
package CarBrands;
class Bmw implements Car {
@Override
public void features() {
// TODO Auto-generated method stub
System.out.println("It is fast.");
}
}
OUTPUT It is fast. It is luxurious.
package VehiclesWithTires; // tight coupling
class VehiclesWithTires{
public static void main(String[] args) {
Vehicle CompleteV = new Vehicle();
CompleteV.vehiclesGotTires();
}
} package VehiclesWithTires; //class vehicle output depends on class tires
public class Vehicle {
public void vehiclesGotTires() {
System.out.println("I have car.");
Tires T = new Tires();
T.vehicles();
}
} package VehiclesWithTires; public class Tires {
public void vehicles() {
System.out.println("My car got 4 wheels.");
}
}
OUTPUT I have car. My car got 4 wheels.