|
-
Jan 8th, 2004, 02:43 PM
#1
Thread Starter
Lively Member
Some Quick VB.NET questions
I need some help with figuring out the best way to do somthing.
In VB6 I would use a UDT like this.
VB Code:
Type PO_Detail
PO_Detail_ID
PO_Number
Line_Description
....
....
End Type
VB Code:
Type Purchase_Order
PO_Number
Vendor_ID
....
....
PO_Detail()
End Type
I would just create the object and add elements as I needed (new po line details). I'm wondering in VB.NET is there a better way?
I am using Structure currently (UDT). Would it be better to use classes?
Somthing like
VB Code:
Public Class PurchaseOrder
Properties, validation, etc
PurchaseOrderDetail() 'Array
End Class
Public Class PurchaseOrderDetail
Properties, validation, etc
End Class
It seems like a much cleaner way of doing it to me, but i'd like some input.
Thanks
-
Jan 8th, 2004, 03:43 PM
#2
Frenzied Member
it depends solely on what your requirements of the software is. A struct in vb.net is a static datatype and I prefer not to use it, because you cannot think of it in OO terms... Structs where great in the old C days when you had to make linked lists, but nowadays everything is made with objects.
If you want to keep it very simple and static, use struct, otherwise create classes. If there are any relations between your data types, classes is the way...
I have programmed vb.net for 1.5 years now, and I have never used the struct Only classes and objects.
Maybe that is because I come from the OO world of C++, perhaps things would have been different if I have been a C programmer...
And as far as i remember, you cannot reference to a struct, only by value (correct me if I am mistaking)
//Henrik
-
Jan 8th, 2004, 05:14 PM
#3
Fanatic Member
structures should be used only for objects that you aren't going to create to many of. If you create a lot of 'em they use up a lot of resources and will slow your app right down. If you are going to create loads of instances uses classes
-
Jan 8th, 2004, 06:30 PM
#4
Thread Starter
Lively Member
Classes seem to be the best way to do what i'm looking to do. I have a few more questions though.
I have a Class for the PurchaseOrderDetails that I'm going to need multiples of in the PurchaseOrder Class. There could be 1, there could be 50. Is there a way to inherit properties from the ArrayList (.add, etc) to the class or do I just have to write my own?
Thanks
-
Jan 9th, 2004, 12:26 AM
#5
Frenzied Member
Hi! if you need a "collection" of objects, I always inherit from the arraylist. There are other ways too, check out the ICollection interface...
public protected class MyClass : inherits ArrayList
end class
//Henrik
-
Jan 12th, 2004, 12:37 PM
#6
Thread Starter
Lively Member
Originally posted by MrNorth
Hi! if you need a "collection" of objects, I always inherit from the arraylist. There are other ways too, check out the ICollection interface...
public protected class MyClass : inherits ArrayList
end class
//Henrik
I've been playing around with this a little and am a bit confused.
Say I have these classes
VB Code:
Class PurchaseOrder
'confusion goes here :)
End Class
Class PurchaseOrderDetail : Inherits ArrayList
'Properties and logic here
End Class
Is that right for the inheritance?
I need multiple Details for each PO.
How would I implement this?
I know I can use a arraylist in the first class and add the second class to the array list. is there a good way to do it?
man i'm confused....
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|