I am here to discuss what are the possible improvement can be made in order to make the following code covering all the principles of programming paradigm ( SOLID , DRY ...etc ). Basically, I am practicing Design Patterns.
Public interface IProduct
{
Int name {get;set;}
Product GetProduct();
}
Public class productA:IProduct
{
productA(string pn)
{
this.name=pn;
}
public int name{get;set;}
Public Product GetProduct()
{ ......}
}
Public class productB:IProduct
{
productB(string pn)
{
this.name=pn;
}
public int name{get;set;}
Public Product GetProduct()
{ ......}
}
Public interface IProductManager
{
ProductA PrepareProductA(string productName);
ProductB PrepareProductB(string productName);
}
Public class ProductManager: IProductManager
{
ProductA PrepareProductA(string productName)
{
return new ProductA(productName);
}
ProductB PrepareProductB(string productName)
{
return new ProductB (productName);
}
}
IoC using AutoFac
var container = new Container();
Container.RegisterType<ProductManager>().As<IProductManager> ().InstancePerhttpRequest();
Controller:
Public HomeComtroller: Controller
{
Private IProductManager _productManager;
Public HomeController( IProductManager productManager)
{
this._productManager= productManager;
}
Public ViewResult GetProductA()
{
var model = _productManager.PrepareProductA( "webapplication");
return view(model);
}
Public ViewResult GetProductB()
{
var model = _productManager.PrepareProductB( "MOBILE");
return view(model);
}
}
Many thanks.
Aucun commentaire:
Enregistrer un commentaire