If you don’t need to do any additional configuration then you should just remove the whole constructor in the subclass. It isn’t required to be able to use the super constructor. Just like you are not required to define all the methods of the super class.
If you do define the sub class constructor then you must call the super constructor otherwise you will break things. When you call it is down to you, but typically you should do it first to allow the sub class constructor to override anything it does you don’t like.
The super constructor makes a copy of the folderitem you pass to it. So at some point you do have 2 instances. One is retained, the other (the one you passed in) is not.
Why do you say that? All it is doing i making sure the initialization code for teh class run…
It seems to me it would be no different than you subclassing a base class you created that has a constructor that does initialization… You still may still want the subclass to be initialized , though you may also want to do some additional things when the instance is created… no need for two instances…
Why would it be otherwise?
Or do you think every time one subclasses a base class 2 instances exist for some period of time?
Actually, the super constructor copies the properties from the FolderItem passed in to the newly instantiated instance of the class you are constructing. It doesn’t create a FolderItem its self. Just as in my example above the A or B constructors do not “create” instances of themselves.
In any call to a constructor a new instance of the class being constructed is created and passed to the constructor as the Self element.
In the copy constructor the second FolderItem is passed in and the constructor must do the job of making a new instance the same as the second one. In my A / B example above a copy constructor would look like this:
Var MyInstance as New B( AnotherB )
Class B inherits A
Sub Constructor( Original as B )
Super.Constructor( Original )
Self.Frog = Original.Frog
End Sub
Class A
Sub Constructor( Original as A )
Self.Fish = Original.Fish
End Sub
There is still only the Original instance (called AnotherB) and the new B created by the Var statement (MyInstance).
AnotherB would exist as long as it stays in scope like any other variable.
Only a single extra instance is created despite the multiple copy constructors.
I may have misunderstood the conversation (Maybe I should read more carefully!)
I was not thinking of the case where one gets a folderitem from a Xojo API like SpecialFolder. In that case one obviously needs to use a copy constructor (or operator convert method) that you write to get a a subclass instance…
I was thinking about a folderitem subclass instantiated via the New Operator. In that case I don’t believe Xojo is (or it least it should not be) internally creating a folderitem base class instance in the super.constructor code and then copying the properties to the subclass instance.
In that case I think the call to super.constuctor is just calling initialization code with no other instance involved…
Of course Xojo COULD be doing something unexpected under the hood… I was just saying I did not think it was or necessarily needed to under the hood to instantiate a folderitem subclass.