Objects by Design Forums Here you can view your subscribed threads, work with private messages and edit your profile and preferences Registration is free! Calendar Find other members Frequently Asked Questions Search Home  
Objects by Design Forums : Powered by vBulletin version 2.3.5 Objects by Design Forums > Main Forums > Object-Oriented Design and Patterns > Classes and parameter passing
  Last Thread   Next Thread
Author
Thread Post New Thread    Post A Reply
RogerRamjet
Junior Member

Registered: May 2005
Location:
Posts: 1

Classes and parameter passing

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.

Report this post to a moderator | IP: Logged

Old Post 05-18-2005 01:46 AM
RogerRamjet is offline Click Here to See the Profile for RogerRamjet Click here to Send RogerRamjet a Private Message Find more posts by RogerRamjet Add RogerRamjet to your buddy list Edit/Delete Message Reply w/Quote
vsatija
Junior Member

Registered: Oct 2005
Location:
Posts: 7

Hi,

In this you have some abstraction that would form some set of classes by the name of:
Computer, Drive, Folder, File.

Each class will have its own set of properties. From the problem statement these classes share aggregation/composition relationship (chose any one as per requirement). This is due to the reason that Computer 'HAS A' Drive. Drive 'HAS A' Folder, Folder 'HAS A' File.

One of the member variable of Computer will be Driver, One of member variable of Drive would be Folder and one of the member variable of Folder would be File. If you want to traverse from bottom to up then you would have to keep reference of the parent class in the contained class.

Very good pattern that can be moulded to satisfy your need is Composite pattern. This is just my suggestion.

I hope this answers to your question

Regards,
Vipin Satija
vsatija

Report this post to a moderator | IP: Logged

Old Post 12-21-2005 08:20 AM
vsatija is offline Click Here to See the Profile for vsatija Click here to Send vsatija a Private Message Find more posts by vsatija Add vsatija to your buddy list Edit/Delete Message Reply w/Quote
All times are GMT. The time now is 04:23 AM. Post New Thread    Post A Reply
  Last Thread   Next Thread
Show Printable Version | Email this Page | Subscribe to this Thread

Forum Jump:
Rate This Thread:

Forum Rules:
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is OFF
vB code is ON
Smilies are ON
[IMG] code is OFF
 

< Contact Us - Objects by Design >

Powered by: vBulletin Version 2.3.5
Copyright ©2000 - 2018, Jelsoft Enterprises Limited.
Copyright 1999-2005, Objects by Design, Inc.