SpankySpanky
Programmer
Hi All
I am new to Object Oriented concepts and patterns. I have a question about how one should handle passing parameters between objects.
Lets say I have a heirarchy of items, Computer which contains Drives, Drives contains Folders, Folders contain Files.
What do I do if in the code of the File, I need to find out the path to the file, which is made up of sections contained in each of the parent parts, ie. I would need Computer\Drive\Folder to give me the complete path.
Do I have to do the following:
Computer creates new Drive object and passes it a string with the computer name.
Then Drive creates a new Folder and passes the Computer name and Drive name to the Folder object.
Then the Folder creates a new file object and passes all this stuff to be stored in the File object.
It seems like good programming practice for each object to hold its own name and not the names of all the parent objects. It doesnt seem logical to duplicate all these items in the File, when it could conceivably ask its parents for it. Is there a way to ask the parent objects for this information?
I primarily use VB .net
Thanks for any advice.
I am new to Object Oriented concepts and patterns. I have a question about how one should handle passing parameters between objects.
Lets say I have a heirarchy of items, Computer which contains Drives, Drives contains Folders, Folders contain Files.
What do I do if in the code of the File, I need to find out the path to the file, which is made up of sections contained in each of the parent parts, ie. I would need Computer\Drive\Folder to give me the complete path.
Do I have to do the following:
Computer creates new Drive object and passes it a string with the computer name.
Then Drive creates a new Folder and passes the Computer name and Drive name to the Folder object.
Then the Folder creates a new file object and passes all this stuff to be stored in the File object.
It seems like good programming practice for each object to hold its own name and not the names of all the parent objects. It doesnt seem logical to duplicate all these items in the File, when it could conceivably ask its parents for it. Is there a way to ask the parent objects for this information?
I primarily use VB .net
Thanks for any advice.