Who owns what Object

  • Thread starter Thread starter AMP
  • Start date Start date
A

AMP

Hello,
Brushing up on my OO.
If Public Class A creates an object, class_b, of type Public Class B,
Can an instance of Class C see class_b without it being passed to it
in a constructor.
What is a realy good book on OO, particularly with a c# bend to it?
Thanks
 
Of course.  But code in class C has to be able to read _some_ variable  
_somewhere_ that stores a reference to the instance "class_b".

Peter,
I've always been confused about what is seen where.
I know about scope, but that only seems to be half the equation, the
other half is what references are available where and waht has to be
passed as opposed to being just referenced.
Thats why I ask about a Quality book on the subject.
Thanks
 
AMP said:
Hello,
Brushing up on my OO.
If Public Class A creates an object, class_b, of type Public Class B,
Can an instance of Class C see class_b without it being passed to it
in a constructor.
What is a realy good book on OO, particularly with a c# bend to it?
Thanks

Not even the instance of A that created class_b can "see" it unless it maintains
a reference to it.

Coding "b_instance = new B()" creates a B and holds a reference in the field
b_instance. Just simply coding "new B()" creates the instance of B but there is
no reference to it retained by the instantiator.

If there is a reference, it can be made available to other objects in various
ways, as Peter has indicated.

HTH,
-rick-
 
Back
Top