I am currently designing a master detail gridview. I have two separate objects defined for them. The parent gridview is binded to the first object and in row databind event I bind the second gridview with the detail object using parent ID.
A lot of examples I see on the internet initialize the details object inside the parent class,
public class Author
{
private string name;
public BooksList books=new BooksList();
public BooksList Books
{
get
{
return emailAddresses;
}
set
{
emailAddresses = value;
}
}
What is the purpose of initializing child class inside the
parent class?Currently, I just bind the parent to a separate object & child to a
separate object manually in my presentation layer & never initialize child objects inside parent class. Is that the wrong way
for OOP ?- What is the recommended way to achieve this task for my gridview?
Damien.
1: Most of the time you want to initialize you objects inside of your class to avoid null reference issues.
2: You confusing you concepts here, as how you present your objects is not really relevant to OOP. The OOP part of the equation is all about what your classes are and how they relate to each other, so yes if there is a relationship between the parent and child classes, then it should be represented in the class structures.
3: Ideally, you would have a class structure that allows you to bind to your datagrid and can automatically generate your hierarchy for your datagrid.