Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
celine scarlett
Ranch Hand
Posts: 93
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1780
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
??? What' wrong with just doing the following ???
 
celine scarlett
Ranch Hand
Posts: 93
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

Thanks for the reply.

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

Many thanks
 
Jeff Albertson
Ranch Hand
Posts: 1780
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Questions like that are best answered by writing a few lines of code to check:
 
celine scarlett
Ranch Hand
Posts: 93
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I'm not sure I understand, but thank you anyway.
 
celine scarlett
Ranch Hand
Posts: 93
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1780
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 93
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

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

 
celine scarlett
Ranch Hand
Posts: 93
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

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



Have I implemented this correctly?
 
Jeff Albertson
Ranch Hand
Posts: 1780
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, but notice you passed two Titles:

public Video(int refNum, Title t, int d, double dp, Title title)
 
celine scarlett
Ranch Hand
Posts: 93
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic