You have public members in Fred and barney....you could fix this by making
barney private and declaring a property that assigns a value to barny.
Remember that encapsulation doesn't deal with what a class does internally
per se, it deals with how other classes can access things inside your class.
And if outside classes can manipulate your members directly, without being
marshalled through a property, then you broke encapsulation.
Is it a bad thing? Generally speaking, yes and I would recommend avoiding
it. Once again, it mainly depends on how its being used----I know many use
Public variables and think properties are a waste of code - I'm not one of
them. I'd use properties and go from there...
HTH,
Bill
".pd." <sp*****@your.peril> wrote in message
news:Xn*****************************@194.83.179.10 2...
If I have a control that adds itself to its container, does that break
encapsulation? Is it a bad thing?
Here's what I mean:
public class fred
{
public barny b;
public fred()
{
b = new barny(this);
}
...
}
public class barny
{
public barny(fred f)
{
...
f.Controls.Add(this);
}
}
Cheers,
.pd.