Re: Custom class know what class owns it
- From: "Ralph" <nt_consulting64@xxxxxxxxx>
- Date: Wed, 4 Oct 2006 21:23:01 -0500
"Dmitriy Antonov" <antonovdima@xxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:%23BlwHsA6GHA.1200@xxxxxxxxxxxxxxxxxxxxxxx
of
"Ralph" <nt_consulting64@xxxxxxxxx> wrote in message
news:Mu-dnav8BK_ng7nYnZ2dnUVZ_s-dnZ2d@xxxxxxxxxxxxxxx
"Usarian M. Skiff" <noemail@xxxxxxxxxx> wrote in message
news:eKlcva%235GHA.508@xxxxxxxxxxxxxxxxxxxxxxx
I'm delving into custom classes in vb.net 1.1
I want all my instances of class B to have a reference to the instance
Iclass A that owns it.
For example, datatables. One of a datatable's properties is Dataset.
wherecan
access the dataset that contains the datatable through that property.
Wrong group.
But this is so wrong, I can't help myself.
You need to do a lot of re-thinking about this. There are occasions
thata
circular reference might actually be a solution, but they are so rare
considered.one shouldn't even consider it until everything else has been
to
It certainly doesn't appear warranted for this situation.
-ralph
I disagree, Ralph. Maybe it is not often (if ever) necessary for a client
get a parent from child, but I often need to have a reference to parentfrom
within a child. If I want to make some call up in object model hierarchyoption?
internally, then without having a reference to parent there are only three
ugly options, which I could imagine:
1. Having a global variable of the topmost (a.k.a. Application) object and
always go down from it, even internally within component.
2. Using Events, even if they are not intended for client.
3. Using Windows messaging mechanism (SendMessage) - very inconvenient and
slow.
None of those three options looks good, do they? Any other [better]
As for the problem with DF - well, "weak" references eliminate the problemknow.
of circular dependencies. For .NET it is not a problem at all, as you
Dmitriy.
I figured I might get that sort of response, as I replied to someone who has
a few more tools (or should I say oopl) available to him, in a newsgroup
(VB) where we are a bit more limited. I have written more 'circular
references' in VB than in any other language (still a very small number),
but that is as they say "another story". Had the OP been using VB I would
have been more guarded in my choice of emphasis.
To your list you forgot to add one more mechanism, which is perhaps the
better solution, and that is to pass a reference/object (or even the
specific data/info) as part of the initialization or contruction process of
the class.
Which is what the OP should probably do - Remember we were told ClassB
*needs* access to this thing - therefore why ever create one without it? It
is still a bad idea in this case however.
[Warning! What follows is pure conjecture as we know little about what the
OP is actually doing. But when have I ever let that stop me .... <g>]
ClassA uses a DataSet <has a>
ClassB uses a DataSet <has a> or should it? Maybe it just needs some bit of
data.
Then we learn..
ClassA uses the services of ClassB <has a>
(In fact 'owns' one)
ClassB uses the services of ClassA <has a>
(bells start to ring.)
Do we really need the services of ClassA or just something it seems to know
about?
Then we learn that ClassA is a "datatable". Which is immediately suspicious
since I doubt a good object "is <ever> a" datatable - more likely it uses
the services of a datatable.
Rather than drag you through a further mire of bad logic, let's cut to the
chase. <g>
I can guarantee you, that whatever ClassB is, IT is likely the 'real' object
(Real? call it the more generalized, the top most, ...). The OP most likely
has it backwards, or these are NOT really separate objects at all. (or even
a 3rd creature is lurking behind the scenes. <g>) In any case the whole
thing is a house of cards and needs a bit of re-thinking.
ClassB has a ClassA
ClassA has a DataSet
ClassB requests services from ClassA
ClassA provides services from a DataSet
Tah Da! No circular reference. And more importantly likely a better OO
solution. The OP's example is the classic case of "How do I implement"
opposed to the correct question "What is it I really need to do"?
That's why I am suggeting that anytime you run into a situation that calls
for a circular reference - you need to back off and do a bit of re-thinking.
-ralph
.
- References:
- Custom class know what class owns it
- From: Usarian M. Skiff
- Re: Custom class know what class owns it
- From: Ralph
- Re: Custom class know what class owns it
- From: Dmitriy Antonov
- Custom class know what class owns it
- Prev by Date: Re: VB / DLL Issues
- Next by Date: Re: recordcount per date ? could you do that?
- Previous by thread: Re: Custom class know what class owns it
- Next by thread: Re: Trying to be 'well behaved' under Vista
- Index(es):