Re: Constructor call constructor

Tech-Archive recommends: Speed Up your PC by fixing your registry



Personnaly, I choose to place all the code in the constructor with all the
parameters.

The constructors with minder parameters are only "shortcuts" for the full
constructor


"Ignacio Machin ( .NET/ C# MVP )" <ignacio.machin AT dot.state.fl.us> a
écrit dans le message de news:euHRrh%23VGHA.424@xxxxxxxxxxxxxxxxxxxxxxx
Hi,

IMO it's better to concentrate all the code in only one constructor,
otherwise you may get errors as you include some code in one variant and
not
the other, cause remember that you usually do more than just assign values
to variables.

In your example, what happens with "FromLog " if the first constructor is
called?
because of that yours contructor with partial parameters should call the
constructor with all the parameters and there you do your init:

public SystemEvent(DateTime p_Heure, String p_Porte, String p_TypeEvt)
:
this (p_Heure, p_Porte, p_TypeEvt, false, false)
{}

public SystemEvent(DateTime p_Heure,String p_Porte,String p_TypeEvt,
bool p_FromLog,bool p_WithVerifEvent) {
this.p_FromLog = p_FromLog;
this.p_WithVerifEvent;
this.p_Heure = pHeure;
this.p_Porte = p_Porte;
this.p_TypeEvt = p_TypeEvt;
}



--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation

"amaca" <public@xxxxxxxx> wrote in message
news:uGmK5U9VGHA.4724@xxxxxxxxxxxxxxxxxxxxxxx
You can do it either way round with constructor chaining:


public class SystemEvent
{

public SystemEvent(DateTime p_Heure, String p_Porte, String
p_TypeEvt)
{
this.p_Heure = pHeure;
this.p_Porte = p_Porte;
this.p_TypeEvt = p_TypeEvt;
}

public SystemEvent(DateTime p_Heure,String p_Porte,String p_TypeEvt,
bool p_FromLog,bool p_WithVerifEvent) : this (p_Heure, p_Porte,
p_TypeEvt)
{
this.p_FromLog = p_FromLog;
this.p_WithVerifEvent;
}

}


Or you can do it the way round you have it, with the constructor with
the
smaller parameter list calling the one with the larger, with default
values. This generates efficient code; calling common methods doesn't.

Andrew








.



Relevant Pages

  • Re: a method to make js have the ability to inherit
    ... but without the implied type-conversion of the string ... that uses the name of a specific constructor. ... programmer has no idea at all what types of object they are ... no reason for ever doing so. ...
    (comp.lang.javascript)
  • Re: Newbie question: Writing your own class
    ... is made by a class's Create constructor method which allocates memory ... FDefinition: string; ... every other descendant of TObject ... Result:= FDefinition; ...
    (comp.lang.pascal.delphi.misc)
  • Re: About speed
    ... property Name: String read fName; ... constructor TProperty.Create; ... fValue: PropertyOfT_DataType; ... constructor Create(other: TPropertyOfT); overload; ...
    (borland.public.delphi.non-technical)
  • Re: a method to make js have the ability to inherit
    ... discriminating but without the implied type-conversion of the string ... makes no use of an object's - constructor - property anyway.) ... programs should serve some known purpose known to the programmer. ... var o = Father.prototype; ...
    (comp.lang.javascript)
  • Re: regex into str
    ... people confronted with it to reject python as language. ... Don't get me wrong - there is a lot of decisions to be made in language ... The only thing you really need is a simple constructor for your undoubtly ... Overloading "" as the string ...
    (comp.lang.python)