public interface MathFunctionI {
public double calculate(double input);
}
public class Sin implements MathFunctionI {
@Override
public double calculate(double input) {
// TODO Auto-generated method stub
return Math.sin(input);
}
}
public class Tan implements MathFunctionI {
@Override
public double calculate(double input) {
// TODO Auto-generated method stub
return Math.tan(input);
}
}
public class Cos implements MathFunctionI {
@Override
public double calculate(double input) {
// TODO Auto-generated method stub
return Math.cos(input);
}
}
public interface CalculatorI {
public double doCalculate(double d);
}
public class MyCalculator implements CalculatorI {
private MathFunctionI f;
public MyCalculator(MathFunctionI f) {
this.f = f;
}
@Override
public double doCalculate(double d) {
return f.calculate(d);
}
}
import org.springframework.beans.factory.BeanFactory;
import org.springframework.context.support.ClassPathXmlApplicationContext;
public class Client {
public static void main(String[] args) {
BeanFactory beanFactory = new ClassPathXmlApplicationContext("applicationContext.xml");
double input = 30;
CalculatorI calculater = (MyCalculator) beanFactory.getBean("sinCalculator");
System.out.println(calculater.doCalculate(input));
calculater = (MyCalculator) beanFactory.getBean("cosCalculator");
System.out.println(calculater.doCalculate(input));
calculater = (MyCalculator) beanFactory.getBean("tanCalculator");
System.out.println(calculater.doCalculate(input));
}
}
<beans xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://www.springframework.org/schema/beans" xsi:schemalocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.5.xsd">
<bean class="Sin" id="sin">
<bean class="Cos" id="cos">
<bean class="Tan" id="tan">
<bean class="MyCalculator" id="sinCalculator">
<constructor-arg ref="sin"> </constructor-arg></bean> <bean class="MyCalculator" id="cosCalculator"> <constructor-arg ref="cos"> </constructor-arg></bean> <bean class="MyCalculator" id="tanCalculator"> <constructor-arg ref="tan"> </constructor-arg></bean> </bean></bean></bean></beans>
Anda baru saja membaca artikel yang berkategori dengan judul Basit bir Spring Uygulaması. Jika kamu suka, janganlike dan bagikan keteman-temanmu ya... By : En Kolay Yolu
Ditulis oleh:
Adsız -
Belum ada komentar untuk "Basit bir Spring Uygulaması"
Yorum Gönder