|
-
January 7th, 2009, 07:55 AM
#6
Re: Calling some code after new?
 Originally Posted by marceln
Why not use some kind of lazy initialization + dependency injection and forget about that second method.
Code:
Sub Main()
Dim Something As New Child()
Something.Parameter1 = "MyParameter"
Something.Initializator()
End Sub
...
Thanks for your suggestion.
The objective is to do hard work in the base class, (which is coded only once), and reduce the work each time someone write an inherited class, or create an instance (which is done much more times).
If the user need to call Something.Initializator(), is the same than force the user to call AfterNew() in any Child constructor class.
The user can't forget to write the Sub Initializator(), because is a MustOverride routine, but it can forget to call the AfterNew, because nothing forces him to do it.
Also, can forget to write Something.Parameter1 = "MyParameter"
My way of doing it also have a problem. The user need to know than
Code:
Initializator(ByRef Things As ChildrenParameters)
gonna be run with the same parameter instance passed to
Code:
Public Sub New(ByRef Things As ChildrenParameters)
All I can do about it, is add a XML comment to Initializator(), and to New(), although is not very safe the programmer will read it.
[Vb.NET 2008 (ex Express)]
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
|