608 Chapter 13 • Creating a Message Board with ADO and XML
Just like ThreadList, PostList contains a Count property, a method to initialize posts in a thread, and a constructor that accepts the ID of the parent object.The only real difference here is that this class gets values from the User table instead of the Thread table. Next, let’s examine the Item function in Figure 13.35.
Figure 13.35 The Item Function (PostList.vb)
Public Function Item(ByVal index As Integer) As Post
Dim myObject As Object = list.Item(index)
If myObject.GetType() Is GetType(Post) Then
'it is already a post, so nothing further is needed
Else
Dim myPost As Post
myPost = New Post(CType(list.Item(index), DataRow)) 'replace the item in the list with
'an actual post object list.Item(index) = myPost
End If
Return CType(list.Item(index), Post)
End Function
In reviewing this Item function, note that it looks remarkably similar to the Item function in the ThreadList class. In fact, it is exactly the same except that it uses Post instead of Thread. Other than that difference, PostList is exactly the same as ThreadList.
Designing the Post Class
So far, you should have noticed most of the classes in our code share a lot of the same ideas: add, update, lists, mimicking the database tables.Well, the Post class is no different. In fact, it is rather similar to both the Board and Thread classes. Let’s take a look at the UML diagram for this class in Figure 13.36.
Just like the other classes, this one is remarkably similar to its brothers—espe- cially the Thread class.The only real difference between this class and the Thread class is that Post has a Body field, pulls its values from the Post table, and doesn’t have any child objects. Let’s take a look at the whole class in Figure 13.37 (which can be found on your CD as Post.vb), as there really isn’t much to it.