What is the best way to return a large amount of related information from a routine?
-
I have a routine for displaying to the user, information on the memory which is installed in their system. This routine is currently encapsulated in a class with each piece of information being returned as a property. The class's instantiated object is only used the once. The routine that provides the class's properties with their information is executed when the class is instantiated from the calling routine requiring the memory information thus:
dim memInfo as new MemoryInformation
. The class's code resides in the Public Sub New(). What I would like to know is, is this the best way to go about implementing this sort of functionality? Should I maybe use a Function and return the info in a collection of some sort or should the code in the class's New sub be moved to a separate method instead? I'm rather new to OO programming and haven't got my head round when is the best time to use a class instead of a function. Any help would be greatly appreciated.No trees were harmed in the posting of this missive; however, a large number of quantum states were changed.
-
I have a routine for displaying to the user, information on the memory which is installed in their system. This routine is currently encapsulated in a class with each piece of information being returned as a property. The class's instantiated object is only used the once. The routine that provides the class's properties with their information is executed when the class is instantiated from the calling routine requiring the memory information thus:
dim memInfo as new MemoryInformation
. The class's code resides in the Public Sub New(). What I would like to know is, is this the best way to go about implementing this sort of functionality? Should I maybe use a Function and return the info in a collection of some sort or should the code in the class's New sub be moved to a separate method instead? I'm rather new to OO programming and haven't got my head round when is the best time to use a class instead of a function. Any help would be greatly appreciated.No trees were harmed in the posting of this missive; however, a large number of quantum states were changed.
I vote for that being the best way. If you have a large amount of information that you need to return, then a class seems to be the way to go. As to whether to put it in the New or another function, I would normally put it into a function and have that function return a
MemoryInformation
class in case you want to reuse your class in a different way later, but I wouldn't begin to state that there's a right or wrong way to do that. -
I vote for that being the best way. If you have a large amount of information that you need to return, then a class seems to be the way to go. As to whether to put it in the New or another function, I would normally put it into a function and have that function return a
MemoryInformation
class in case you want to reuse your class in a different way later, but I wouldn't begin to state that there's a right or wrong way to do that.Thanks for the reply. I've been thinking along similar lines. My routines 'work' as I have them implemented at the moment. I was wondering at the time I was writing the routines whether it was the 'best' way. I've been 'brought up' as a procedural programmer and find OO programming a complete paradigm shift to what I'm used to!
No trees were harmed in the posting of this missive; however, a large number of quantum states were changed.