A furniture can be made of Wood, metal or may be something material (in future). The furniture can be of different types like chair, table etc Now a wooden furniture must be tested against charcoal properties. A metal furniture must be testes against electricity conductivity. How will we design it's OOD.
I don't know whether following approach is correct or not.
Interface MaterialTesting { Testing ();}
Public class WoodTesting implements MaterialTesting
{ // define body for wood testing method testing(); // }
Public class MetalTesting implements MaterialTesting
{ // define body for metal testing method testing(); // }
Public Class Furniture
{
WoodTesting woodtestObject;
MetalTesting metaltestObject;
Furniture(MaterialType material)
{
if material isInstanceOf(WoodTesting)
woodtestObject = new WoodTesting ();
if material isInstanceOf(MetalTesting)
metaltestObject= new MetalTesting ();
}
}
Public Class Chair extends Furniture
{
Chair(MaterialType material)
{
super();
}
}
Class DriverClass{
PSVM()
{
Furniture woodchair = new Chair(wood);
Furniture metaltable = new Table(metal);
woodchair.Testing();
}
And we have to declare another MaterialType class.
Also, please tell how it can be implemented using Factory design pattern.
Aucun commentaire:
Enregistrer un commentaire