090923 TB single object one-to-Multiple Association

Source: Internet
Author: User

When programming, the design of Object-related APIs may be problematic, so there is no solution yet.
The problem is as follows:

Using system;
Using system. Collections. Generic;
Using system. LINQ;
Using system. text;

Namespace consoleapplication
{
/// <Summary>
/// Fill in the corresponding content in notimplement's method/attribute to ensureProgramNo exception is thrown.
/// (That is, the parent attribute, addchild method, and removechild method .)
///
/// Other information cannot be modified.Code.
/// </Summary>
Class Program
{
Static void main (string [] ARGs)
{
Parent parenta = new parent ();
Parent parentb = new parent ();
Child child = new child ();

Parenta. addchild (child );

Child. Parent = parentb;
Assert (parenta. Children. Count = 0, parentb. Children. Count = 1, child. Parent = parentb );

Parenta. addchild (child );
Assert (parentb. Children. Count = 0, parenta. Children. Count = 1, child. Parent = parenta );

Child. Parent = NULL;
Assert (parentb. Children. Count = 0, parenta. Children. Count = 0, child. Parent = NULL );
}

Static void assert (Params bool [] values)
{
Foreach (VaR value in values)
{
If (value = false)
{
Throw new exception ();
}
}
}
}
Class Parent
{
Private list <child> _ children;

Public parent ()
{
This. _ Children = new list <child> ();
}

Public ilist <child> Children
{
Get
{
Return new system. Collections. objectmodel. readonlycollection <child> (this. _ children );
}
}
Public void addchild (child)
{
Throw new notimplementedexception ();
}
Public void removechild (child)
{
Throw new notimplementedexception ();
}

}
Class child
{
Private parent _ parent;

Public parent
{
Get
{
Throw new notimplementedexception ();
}
Set
{
Throw new notimplementedexception ();
}
}
}
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.