Jump to content

  • Log In with Google      Sign In   
  • Create Account

Calling all IT Pros from Canada and Australia.. we need your help! Support our site by taking a quick sponsored surveyand win a chance at a $50 Amazon gift card. Click here to get started!


Mikea15

Member Since 05 Dec 2008
Offline Last Active Today, 08:18 AM

#5145178 Constructor Chaining Order to Parameters or Parameterless.

Posted by Mikea15 on 07 April 2014 - 03:39 PM

So I guess, I would have to re-think on how much control those classes provide. Thank you :)




#5144952 Constructor Chaining Order to Parameters or Parameterless.

Posted by Mikea15 on 07 April 2014 - 02:16 AM

Okay, so there is no "best way" to do it. That's what I wanted to know. smile.png

 

Thanks for the feedback. smile.png

 

Edit:

To get a better view. Here's the main difference with another class.

public X( )
{
    Left = 0;
    Right = 0;
    BreakLeft = false;
    BreakRight = false;
    BreakTime = 0;
}

public X(int speed)
    : this( )
{
    Left = speed;
    Right = speed;
}

public X(int left, int right)
    : this( )
{
    Left = left;
    Right = right;
}

public X(int left, int right, int time, bool breakWheel)
{
    Left = left;
    Right = right;

    BreakLeft = breakWheel;
    BreakRight = breakWheel;

    BreakTime = time;
}

public X(int left, int right, int time, bool breakLeft, bool breakRight)
{
    Left = left;
    Right = right;

    BreakLeft = breakLeft;
    BreakRight = breakRight;

    BreakTime = time;
}

And Method 2:

public X( )
    : this( 0 )
{

}

public X(int speed)
    : this( speed, speed )
{
    
}

public X(int left, int right)
    : this( left, right, 0, false )
{

}

public X(int left, int right, int time, bool breakWheel)
    : this( left, right, time, breakWheel, breakWheel )
{

}

public X(int left, int right, int time, bool breakLeft, bool breakRight)
{
    Left = left;
    Right = right;

    BreakLeft = breakLeft;
    BreakRight = breakRight;

    BreakTime = time;
}

For this particular case. This is the better approach. It has less code, Its easier to maintain and is cleaner. smile.png




#4983754 Stuck in a programmers rut.

Posted by Mikea15 on 25 September 2012 - 03:47 PM

One thing you can do is leave an error, and a comment, so the next time you get to work on the project, you compile, know where the error is, read the comment, and everything will be clear in your head.

:)


PARTNERS