Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7684749
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T19:05:58+00:00 2026-05-31T19:05:58+00:00

See the the ? mark for the question. public class Person { public Int16

  • 0

See the the ? mark for the question.

public class Person 
{
    public Int16 ID { get; private set; }
    public string Name { get; private set; }
    public List<Toy> Toys { get; private set; }
    public Person(Int16 id, string name, List<Toy> toys)
    { ID = id; Name = name; Toys = toys; } 
}
public class Toy
{
    public string Name { get; private set; }
    public Person Owner { get; private set; }
    public Toy(Person owner, string name)  
    { Owner = owner; Name = name; }
}

The problem is with the Person CTOR. How to pass toys to the Person ctor? Toy needs Owner in the Toy ctor but that Owner has not yet been built yet.

I understand I can move Toys out of the Person CTOR and make the set public. Assume you only get the toys you are born with – the private set; has a purpose. And I understand that what I am asking for may not be possible.

Like anyone really cares but Toy only needs to know it Owners name so I may just modified Toys.

  public class Toy
  {
     private Person owner;
     private string ownerName;

     public string Name { get; private set; }
     public String OwnerName 
     { 
        get
        {
           if (!string.IsnullOrEmpty(ownerName)) return ownerName;
           elseif (owner != null) return owner.Name;
           else throw new exception("homelesstoy");
     }
     public Toy( string name, Person owner)  
     { 
         Name = name; Owner = owner;
         // new toy need to write it to DB 
     }
     public Toy( string name, string _ownerName)  
     { 
         Name = name; ownerName = _ownerName;
     }
  } 

In a whacked kind of way this is better. If my toy is is my car and they have my keys I don’t want them to know my address. From my name the police can find me if the car is recovered.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T19:05:59+00:00Added an answer on May 31, 2026 at 7:05 pm

    Why is the setter on Owner private? I can understand your point about the setter on Toys in the Person class.

    If you removed that constraint, you could create a backing store (full property) and then loop the toys list in the Person constructor and do item.Owner = this.

    public class Toy
    {
        private Person _owner = null;
        public string Name { get; private set; }
        public Person Owner { 
             get { return _owner; }; 
             set {
                  if(_owner != null) throw new InvalidOperationException("No Stealing");
                  _owner = value;
             }
        }
        public Toy(Person owner, string name)  
        { Owner = owner; Name = name; }
    }
    

    This would allow you to set Owner only once and subsequent calls to the setter would be exceptional. You wouldn’t need to change the constructor, because you could still do:

    Toy batman = new Toy(null, "Bruce");
    

    One problem that I see is that this Toy-Owner relationship doesn’t model the real world. Children are sometimes born with a slew of toys at their disposal, but toys are hardly ever manufactured with an immediate owner. Even after a toy is created and given to someone, it can be given to someone else.

    I think the conceptual details are tripping you up logically.

    edit:
    forgot the constructor…

    public Person(Int16 id, string name, List<Toy> toys)
    { 
        id = ID; 
        Name = name; 
    
        foreach(Toy item in toys) {
            item.Owner = this;
        }
    
        Toys = toys; 
    } 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Please see the following code to understand my question better. class compareByValue { public:
I see that Spring has a @Required annotation to mark member variables in beans
(see here for the problem I'm trying to solve) How do you get hibernate
See the question. I want to see the methods and classes offered by a
In the Eclipse Helios Java Package Explorer, I see the Java class icons display
See also related question: How do you debug Qt layout problems I've got some
******QUESTION WAS EDITED, Please see below** I am running into a problem when I'm
This question is in relation to a previous question I've asked ... see SQL
please consider following code #include <iostream> using namespace std; class Digit { private: int
So I want to search through a string to see if it contains the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.