Java Best Practice.
It’s been a long time we have been moving with a traditional way of Java programming which makes the programs tightly coupled and also leads the program a hassled one to be modified or to make generic.
Let us see a traditional program followed by a modern programming techniques to make programs more generic and expendable… we also call it best practice of Java programming in oppose to traditional style of programming.
Traditional:
package traditional;
public class Traditional {
public static void main(String[] args) {
System.out.println("Traditional Programming!!!");
}
}
Modern:
package modern;
import java.io.PrintStream;
final class Source {
private final String message;
public Source(String message) {
this.message = message;
}
public String getMessage() {
return message;
}
}
class Destination {
public void write(PrintStream out, String message) {
out.println(message);
}
}
public class Mordern {
public static void main(String[] args) {
Source source = new Source("Modern Programming!!!");
Destination destination = new Destination();
destination.write(System.out, source.getMessage());
}
}
- Labels: Java SE
- (0) Comments
Subscribe to:
Post Comments (Atom)
0 comments:
Post a Comment