Powered by Blogger.

Factory Design Patterns

No comments :
Introduction
Factory Design Patterns follows the principal of “Define an interface or abstract class for creating an object but let the subclasses decide which class to instantiate”. The factory design Pattern is also known as virtual constructor.
Example:
We have three Milk Brand that describes the cost. Here we have three different Milk Brands namely, AMUL, SUDHA, AAVIN, along with their rate. Let us find milk brand of sale an each packet.

Public String MilkBrandCost(Stirng productame){
if(productame == null){  
             return null;  
            }  
If(productame.equals("AMUL")){
return "AMUL DARY and MRP:28";
}

If(productame.equals("SUDHA")){
return "SUDHA DARY and MRP:23";
}

If(productame.equals("AAVIN")){
return "AAVIN DARY and MRP:25";
}

}
....
return null;  


No comments :

Post a Comment

Please Write a Message for Programming or something Related issues.