Alex Rivera | Logout

Should a class contain a collection of itself?

Asked 2010-11-25T18:01:10.513
10

Is it poor design to have a class containing a collection of itself like in a List<> for C#? Why is this and what is a better approach and why?

EDIT: More specifically, I have a class called Product and a method in the class called GetProducts() that returns a List collection. It good be grabbing the products from a database, flat file, or xml... not sure yet.

Thanks!

c#
Edit
Report

1 Answer

0

Sure that's generally fine. That's generally the sensible way of implementing a tree in an OOP-y way; a TreeNode has to contain a List<TreeNode> m_Children field in it so the node knows what it's children are for tree traversal.

answered 2010-11-25T18:04:29.327

Your Answer