Closed Coupled : Decouple « Spring « Java Tutorial






File: Main.java

import java.io.PrintStream;

public class Main {
  public static void main(String[] a) {
    MessageData source = new MessageData("Hello, world");
    MessageReporter destination = new MessageReporter();
    destination.write(System.out, source.getMessage());
  }
}

final class MessageData {
  private final String message;

  public MessageData(String message) {
    this.message = message;
  }

  public String getMessage() {
    return message;
  }
}

class MessageReporter {

  public void write(PrintStream out, String message) {
    out.println(message);
  }

}
  Download:  Spring-ClosedCoupled.zip( 2,562 k)








28.1.Decouple
28.1.1.Spring Style Decouple
28.1.2.Decouple With Interface
28.1.3.Closed Coupled