Jump to content

  • Log In with Google      Sign In   
  • Create Account

Interested in a FREE copy of HTML5 game maker Construct 2?

We'll be giving away three Personal Edition licences in next Tuesday's GDNet Direct email newsletter!

Sign up from the right-hand sidebar on our homepage and read Tuesday's newsletter for details!


We're also offering banner ads on our site from just $5! 1. Details HERE. 2. GDNet+ Subscriptions HERE. 3. Ad upload HERE.


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