最近我參加了一次採訪,並給出了這個問題:設計類
問:與您以下實體,設計類圖或框架代碼:
該實體是:
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;}
}
但我仍可以看到許多東西從上面的骨架代碼錯過了。
- 我如何能與
Garment
與其他實體(對象關係!?) - 什麼可以的功能
MakeShirt()
和MakePant()
返回類型? - 在回答這些問題時,哪種方法最好?換句話說,如何處理這些類型的問題?
對此有任何意見。 (如果不是在這裏問正確的問題,請讓我知道這個移動到右側計算器網站!)
嗯。襯衫是一種面料嗎?我敢打賭,這是一件服裝,而且這件服裝*有一塊織物。 – spender
襯衫,褲子是服裝。服裝是用織物製成的。 – Anirudha
@spender:假設襯衫是一種面料,您能否指導我如何修改我的課程? –