« Previous | 2 | | 4 | Next »

Spring Tightly Coupled Application Example

Contest.java

package com.jtc;
public interface Contest {
public String promptQuestion();
}

StrutsContest.java

package com.jtc;
public class StrutsContest implements Contest {
@Override
public String promptQuestion() {
return "Who invented Struts?";
}
}

SpringContest.java

package com.jtc;
public class SpringContest implements Contest {
@Override
public String promptQuestion() {
return "Who invented Spring?";
}
}

ContestService.java

package com.jtc;
public class ContestService {
//here you need to create the object for which class.
private Contest contest = new StrutsContest();
public void askQuestion() {
System.out.println(contest.promptQuestion());
}
}

ContestApplication.java

package com.jtc;
public class ContestApplication {
public static void main(String[] args) {
ContestService contestService = new ContestService();
contestService.askQuestion();
}
}

Add Below Libraries
commons-logging-1.1.1
nblibraries.properties
org.springframework.beans-3.1.0.RC1
org.springframework.context.support-3.1.0.RC1
org.springframework.context-3.1.0.RC1
org.springframework.core-3.1.0.RC1
org.springframework.expression-3.1.0.RC1
org-netbeans-modules-java-j2seproject-copylibstask
OutPut
Who invented Struts?
If you will change object to SpringContest then output will be:
Who invented Spring?

Note:

This example is for tight coupling please also check for loose coupling my next example.
« Previous | 1 | 2 | 3 | Next »


copyright © 2014 - all rights riserved by javatechnologycenter.com