R
Rob Meade
Hi all,
I've been writing some .net classes at work now for a while and was feeling
confident in my approach - until I attended a MS ASP.Net course! )
Before the course, if I was going to create perhaps something that needed an
"item" object, and also a collection of those items, I'd write 2 classes,
the first for the individual items, the second as a collection class which I
would then add all of the individual items to.
For example..
Public Class Book
Private _title as string
Private _author as string
.....
End Class
Public Class Books
Private _collection as collection
....
End Class
So, perhaps I'd be iterating through a recordset from a database, and as I
iterated creating a new "book" and adding it to "books" - then later on I
may do something with my "books" class, iterate through and pull out the
individual books etc...
On the coures I attended they seemed to wrap all this up in the same class -
now to me that makes sense but I am having some problems trying to do it!
For exampe, there would be a class which also had the collection as part of
it...
Public Class Book
Private _title as string
Private _author as string
Private _collection as collection
...
End Class
Now, as I said, this makes sense to me, ie everything to do with this item
in the one place, plus I'd be writing some code that looked like this...
For Each Book In Books.Collection
Which looks nice )
My problem is that if the class is an individual item AND a collection, when
I instantiate a new one, I'd be creating an empty collection object for each
book, then later on I'd be creating a new instance of the same object to use
the collection properties of it, adding the individual instance to it (with
the empty collection)...
Can someone advise me on the best approach for this please - I feel like I'm
starting to go around in circles!
Thanks in advance for any help you can offer,
Regards
Rob
I've been writing some .net classes at work now for a while and was feeling
confident in my approach - until I attended a MS ASP.Net course! )
Before the course, if I was going to create perhaps something that needed an
"item" object, and also a collection of those items, I'd write 2 classes,
the first for the individual items, the second as a collection class which I
would then add all of the individual items to.
For example..
Public Class Book
Private _title as string
Private _author as string
.....
End Class
Public Class Books
Private _collection as collection
....
End Class
So, perhaps I'd be iterating through a recordset from a database, and as I
iterated creating a new "book" and adding it to "books" - then later on I
may do something with my "books" class, iterate through and pull out the
individual books etc...
On the coures I attended they seemed to wrap all this up in the same class -
now to me that makes sense but I am having some problems trying to do it!
For exampe, there would be a class which also had the collection as part of
it...
Public Class Book
Private _title as string
Private _author as string
Private _collection as collection
...
End Class
Now, as I said, this makes sense to me, ie everything to do with this item
in the one place, plus I'd be writing some code that looked like this...
For Each Book In Books.Collection
Which looks nice )
My problem is that if the class is an individual item AND a collection, when
I instantiate a new one, I'd be creating an empty collection object for each
book, then later on I'd be creating a new instance of the same object to use
the collection properties of it, adding the individual instance to it (with
the empty collection)...
Can someone advise me on the best approach for this please - I feel like I'm
starting to go around in circles!
Thanks in advance for any help you can offer,
Regards
Rob