Question about extract class from parameters

I saw the video with R# tips and tricks and saw the refactor action: 
extract class from parameters.
I have a question about why it gives this end result.

I start with this methods:
public void Test(int a, int b, bool c)
{
}
public void Invoke()
{
     Test(1 ,2, true);
}

And this will give me:

public class TestParams
{
     private int _A;
     private int _B;
     private bool _C;

     public TestParams(int a, int b, bool c)
     {
          _A = a;
          _B = b;
          _C = c;
     }

     public int A { get { return _A; } }
     public int B { get { return _B; } }
     public bool C { get { return _C; } }
}

public void Test(TestParams testParams)
{
          
}

public void Invoke()
{
     Test(new TestParams(1, 2, true));
}


To me the resulting invoke looks worse instead of better.
I found the page 
http://www.jetbrains.com/idea/webhelp/introduce-parameter-object.html it 
mentions: "Introducing a parameter object is useful if the number of 
parameters passed to a method has grown too large, or if the parameters 
have become complex enough ..."

The problem it tries to fix seems to be to reduce number of arguments or 
make it easier to read or use.

I expected class initializers would be used. That would also need 
property-setters, a default constructor and give the following:

public void Invoke()
{
     Test(new TestParams{A=1, B=2, C=true});
}

That would make the calling more verbose and therefor maybe more clear. Am 
I missing something?

I would love to learn something new and understand the reasons.

Arnold Nelisse

1 comment
Comment actions Permalink

Hello Arnold,

It's just the way it works at the moment. You're welcome to put a feature
request through http://youtrack.jetbrains.net/issues/RSRP for an option to
implement it via object initializer. Thank you!

Andrey Serebryansky
Senior Support Engineer
JetBrains, Inc
http://www.jetbrains.com
"Develop with pleasure!"

I saw the video with R# tips and tricks and saw the refactor action:
extract class from parameters.
I have a question about why it gives this end result.
I start with this methods:
public void Test(int a, int b, bool c)
{
}
public void Invoke()
{
Test(1 ,2, true);
}
And this will give me:

public class TestParams
{
private int _A;
private int _B;
private bool _C;
public TestParams(int a, int b, bool c)
{
_A = a;
_B = b;
_C = c;
}
public int A { get { return _A; } }
public int B { get { return _B; } }
public bool C { get { return _C; } }
}
public void Test(TestParams testParams)
{
}

public void Invoke()
{
Test(new TestParams(1, 2, true));
}
To me the resulting invoke looks worse instead of better.
I found the page
http://www.jetbrains.com/idea/webhelp/introduce-parameter-object.html
it
mentions: "Introducing a parameter object is useful if the number of
parameters passed to a method has grown too large, or if the
parameters
have become complex enough ..."
The problem it tries to fix seems to be to reduce number of arguments
or  make it easier to read or use.

I expected class initializers would be used. That would also need
property-setters, a default constructor and give the following:

public void Invoke()
{
Test(new TestParams{A=1, B=2, C=true});
}
That would make the calling more verbose and therefor maybe more
clear. Am  I missing something?

I would love to learn something new and understand the reasons.

Arnold Nelisse



0

Please sign in to leave a comment.