aspose file tools*
The moose likes Beginning Java and the fly likes Creating a pointer/reference to another object - any help!! Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Creating a pointer/reference to another object - any help!!" Watch "Creating a pointer/reference to another object - any help!!" New topic
Author

Creating a pointer/reference to another object - any help!!

celine scarlett
Ranch Hand

Joined: Nov 06, 2005
Posts: 93
Hi,

I'm trying to design a basic video loans program, and currently have a class for the titles of the videos. I need to create a link to this from the Video class, which stores loan information on the videos being borrowed.

Basically, any idea how I can create a pointer/reference to the Title object from the Video class?

I also need to add a boolean to say whether the video is available or not.

I know these are a bit simple, but any help would really be appreciated.

My code so far is as follows,

1. The Video Class



and the code for my Title class is as follows,



Any help really appreciated!!
Jeff Albertson
Ranch Hand

Joined: Sep 16, 2005
Posts: 1780
??? What' wrong with just doing the following ???


There is no emoticon for what I am feeling!
celine scarlett
Ranch Hand

Joined: Nov 06, 2005
Posts: 93
Hi,

Thanks for the reply.

Will that give me all the information from the Title class?

Many thanks
Jeff Albertson
Ranch Hand

Joined: Sep 16, 2005
Posts: 1780
Questions like that are best answered by writing a few lines of code to check:
celine scarlett
Ranch Hand

Joined: Nov 06, 2005
Posts: 93
Hi,

I'm not sure I understand, but thank you anyway.
celine scarlett
Ranch Hand

Joined: Nov 06, 2005
Posts: 93
Hi,

Thanks for all the help. I've tried to implement the reference to the Title object as follows,



Do you think this is suitable, and will it work?

The code for the Video class is now as follows,



Any help appreciated!!
Jeff Albertson
Ranch Hand

Joined: Sep 16, 2005
Posts: 1780
I think most programmers would pass a Title object, rather that its attributes
to a Video constructor:

This way, Video doesn't have to know details of the Title class and if
you add attributes to Title (or subclass it), Video won't have to change.
You can share a Title object between Video objects, as well.
celine scarlett
Ranch Hand

Joined: Nov 06, 2005
Posts: 93
Hi,

I think I see what you mean now. Thanks for all the help. It is much appreciated!!

celine scarlett
Ranch Hand

Joined: Nov 06, 2005
Posts: 93
Hi,

When you say pass an object, do you mean the following,



Have I implemented this correctly?
Jeff Albertson
Ranch Hand

Joined: Sep 16, 2005
Posts: 1780
Yes, but notice you passed two Titles:

public Video(int refNum, Title t, int d, double dp, Title title)
celine scarlett
Ranch Hand

Joined: Nov 06, 2005
Posts: 93
Hi,

Yes, you're right. I missed that one. I shall correct it straight away. Now, I've just got to sort out the best way to implement the boolean value for this class.

Thank you so much for all your help. It is much appreciated!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Creating a pointer/reference to another object - any help!!