I wrote a code to represent the factory design pattern as below:
package com.factory2;
public interface CreditCheck {
Double creditLimit(int id);
}
package com.factory2;
public class CreditCheckFactory {
public boolean isAgencyUp(){
return true;
}
public CreditCheck createCreditCheck(){
if(isAgencyUp()){
return new CreditCheckOnline();
}else{
return new CreditCheckOffline();
}
}
}
package com.factory2;
public class CreditCheckOffline implements CreditCheck{
public Double creditLimit(int id){
return 21.00;
}
}
package com.factory2;
public class CreditCheckOnline implements CreditCheck{
public Double creditLimit(int id){
return 20.00;
}
}
package com.factory2;
public class Test {
public static void main(String[] args){
CreditCheckFactory ccf = new CreditCheckFactory();
CreditCheck cc1 = ccf.createCreditCheck();
System.out.println(cc1.creditLimit(8));
CreditCheck cc2 = ccf.createCreditCheck();
System.out.println(cc2.creditLimit(8));
}
}
However I require some expert advice on whether my code does comply the factory design pattern. Some say that
the Factory class that I written should consist of static methods.
Your help is kindly appreciated.
Thank You.