Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

class design

Status
Not open for further replies.

laailalalaa

Programmer
Mar 2, 2009
2
FR
i 'm reading smn else's C# code. i have smth (oversimplified) like this:
class A {instaceOfClassB; }
class B {instanceOfClassA; }

what's the point in doing that? also why doesn't this generate an infinite pointer chain (define instance of A, which would contain an instance of B (pointing to B), which again would contain an instance of A (pointing to A) aso asf)?
 
it depends on the context. perhaps if you form the question in a specific context rather than generalities we could comment. however what you have here is useless. As with many things in life, there isn't one right way to do things. This is merely one option to model the context.

there isn't an infinite pointer chain, because instances of objects are unique.
Code:
class Foo
{
   public Bar B;
}
class Bar
{
   public Foo f;
}

var f = new Foo();
var b = new Bar();
f.B = b;
b.F = f;
or
Code:
var f = new Foo{B = new Bar{F = new Foo{B = new Bar()}}};
f.B.F.B.F = f;

p.s. this is a professional forum not facebook or twitter. use of smn, asf, smth makes you come across as juvenile.

Jason Meckley
Programmer

faq855-7190
faq732-7259
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top