Recently I had attended an interview and was given this question:
Question: With the following entities with you, design a class diagram or skeleton code:
The entities are:
garment
shirt
pant
fabric
buttons
zip
The best I could do was this:
class Shirt : Fabric
{
Buttons buttons {get;set;}
//Inherits all Fabric methods
MakeShirt()
{
//make a shirt here
}
}
class Pant : Fabric
{
Buttons buttons {get;set;}
// Inherits all Fabric methods
MakePant()
{
//Make a pant here
}
}
class Fabric
{
private MaterialType materialType {get;set;}
private FabricType fabricType {get;set;}
Fabric(MaterialType mType, FabricType fType)
{
this.materialType = mtype;
this.fabricType = fType;
}
public GetFabricMaterial();
public GetFabricType();
}
class Garment : IGarment
{
Price price {get;set;}
Audience audience {get;set;}
}
enum FabricType
{
Fabric_Formal,
Fabric_Casual,
}
enum MaterialType
{
Fabric_Cotton,
Fabric_Silk,
Fabric_Wool,
}
class Buttons
{
Color color {get;set;}
Shape shape {get;set;}
}
class Zip
{
Color color {get;set;}
Size size {get;set;}
}
But still I can see many things missing out from the above skeleton code.
- How can I relate
Garment
with the other entities (Object relationship! ?) - What can be the return type of functions
MakeShirt()
andMakePant()
? - While answering these questions, what approach is best ? In other words, how to approach these type of questions ?
Any inputs on this is appreciated. (If this is not the right question to be asked here, kindly let me know to move this to the right stackoverflow site!)