I'm designing a product category management feature for my project. Basically, a product category has got the following properties:
- ID
- Name
- Parent category
- Child categories
Now I want to display all product categories as a tree view on the UI. It looks like:
- Electric devices
- Computer
- Desktop
- Laptop
- Server
- Smart phone ...
- Computer
- Clothes
- Men
- Jean
- Shirt
- Women
- Dress
- Men
- ...
Currently, I'm designing a class ProductCategory using tree data structure to represent the whole product category tree as below:
public class ProductCategory
{
public int Id {get;set;}
public string Name {get;set;}
public ProductCategory Parent {get;set;}
public List<ProductCategory> Children {get;set;}
}
I don't know whether composite design pattern can apply to this case or not?
What are differences between tree data structure and composite design pattern?
Thanks
Tuan
Aucun commentaire:
Enregistrer un commentaire