Factory Pattern

This will create an interface first and the subclasses decide which class needs to be instantiated. The same interface will be used by 2 different classes for different purpose.Let me explain this with an example,so that you can understand it crystal clear.

 public interface IMILK
{
void hotdrinks();
}
class clsmakingTea:IMILK
{
public void hotdrinks()
{
write("Here milk is used to put TEA");
}
}
class clsmakingCoffee:IMILK
{
public void hotdrinks()
{
write("Here MILK is used to put COFFEE")
}
  
}

Now create one subclass called clsfactorydrinks and create method called getdrinktype() which will ask for input ,whether Tea or Cofee,

public class clsfactorydrinks
{
static public IMILK getdrinktype(int drinktype)
{
imilk iobjmilk;
if(drinktype==1)
{
iibjmilk = new clsmakingTea();
}
elseif(drinktype==2)
{
iobjmilk = new clsmakingCoffee();
}
return iobjmilk;
}
}

Actual client call,
imilk iobjmilk;
int drinktype;
write("enter 1 for Tea and 2 for Coffee");
drinktype=console.readline();
iobjmilk=clsfactorydrinks.getdrinktype(drinktype);
iobjmilk.hotdrinks();