|
-
Sep 14th, 2007, 04:15 PM
#1
Strange class construct.
I'm reviewing some template generated code, and have come across one of the strangest class constructs I have ever seen, so I figured I'd post it on here to get peoples opinions. The construct looks like this:
vb Code:
Public Class A
public bt as B
Public sub New ()
bt=Nothing
end sub
'The other class is defined within A:
Public Class B
public ba as A
public sub New(anA as A)
ba = anA
ba.bt = Me
end sub
end class
End Class
In case anyones confused by the simplicity, I reduced the whole thing to a minimal example. All the pieces are there, and the relationships between the objects are preserved, but there is plenty more to the second class (though to be fair, there isn't much more to the first class). Mostly, the second class raises lots of events.
Thus you see that B is defined within A, and A has a member of type B, while B has a member of type A. The B member of A is Nothing when A is created, but when B is created, the two objects are members of each other. Normally, I would simply say that there is no purpose for having two classes in this situation, but there are a couple of reasons for some of this code:
1) There could be numerous objects of type B in type A, though typically there is only one, so combining A and B doesn't necessarily make good sense, as there could be many B instances combined into A.
2) B is defined within A for no very good reason that I can see. The definition of many of the pieces of B are dependent on the name of A, but this is all template derived code, so generating B outside of A would really not take any more time.
So my question is largely: Has anyone ever seen anything like that before, and is there any advantage of creating something this way, with each object being a member of the other object?
Last edited by Shaggy Hiker; Sep 14th, 2007 at 04:18 PM.
My usual boring signature: Nothing
 
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|