Jump to content

  • Log In with Google      Sign In   
  • Create Account

FREE SOFTWARE GIVEAWAY

We have 4 x Pro Licences (valued at $59 each) for 2d modular animation software Spriter to give away in this Thursday's GDNet Direct email newsletter.


Read more in this forum topic or make sure you're signed up (from the right-hand sidebar on the homepage) and read Thursday's newsletter to get in the running!


Mikea15

Member Since 05 Dec 2008
Offline Last Active Oct 06 2014 12:57 PM

#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