0

Hello

I've got this Videorental code.

The flow:
1. Another user wants to rent a video.
2. Hes Videorental creates a new Video object with a Rent object,
which sets he the renter and the other user the owner of the Video.

The User object has Videorental object, it has Video objects and some Video objects have Rent object. There isn't any inheritance going on.

Now I don't know How could I get data from a higher object, in this case the User.
The creation of the Video object takes place in Videorental.
I need to get the info of the owner of this Videorental, specifically the id.

Thanks

Attachments VideoRental.jpg 37.07 KB
2
Contributors
2
Replies
3
Views
7 Years
Discussion Span
Last Post by Klaurac
1

You will need a reference to the UserId in your VideoRental class, then when you assign the VideoRental to the User you update the VideoRental object's UserId to match.

Here's how I would do it:

class User
{
  public GUID Id
  {
    get;
    set;
  }
  private VideoRental m_rental;
  public VideoRental VideoRental
  {
    get
    {
      return m_rental;
    }
    set
    {
      m_rental = value;
      m_rental.UserId = Id;
    }
  }
  // ...
}
class VideoRental
{
  public GUID UserId
  {
    get;
    set;
  }
  // ...
}
0

Thanks, it made me think.
I thought if I made the program scheme, the other way.
Instead of the User having a Videorental object, maybe it would benefit if the Videorental had a User object.
Since the Videorental is in central position in my program, not the user.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.