Factory class with given specs
I've the foll. requirement for one of the applications I'm working on in Java.

Have a factory class C, having the foll. method create(int src), that creates objects of classes A and B.
The method creates object of class A if src=1, object of class B if src=2.
Ensure no other class other than F can create objects of A and B.

I cannot use reflection.

This is what I tried till now.

<code>

class C{

 private int src;

 public c(){
  …//Default constructor
}

public create (int src){
 
 if(src = 1){
  A aobj = new A();
}
else if (src=2){
 B bobj = new B();
} 

} 

} 

</code>
  
How can I improve the class defination to make sure its more consistent with original specs?

Thanks.
Factory class with given specs
===

I've the foll. requirement for one of the applications I'm working on in Java.

Have a factory class C, having the foll. method create(int src), that creates objects of classes A and B.
The method creates object of class A if src=1, object of class B if src=2.
Ensure no other class other than F can create objects of A and B.

I cannot use reflection.

This is what I tried till now.

<code>

class C{

 private int src;

 public c(){
  …//Default constructor
}

public create (int src){
 
 if(src = 1){
  A aobj = new A();
}
else if (src=2){
 B bobj = new B();
} 

} 

} 

</code>
  
How can I improve the class defination to make sure its more consistent with original specs?

Thanks.