Generating a New Type using Refactoring

Hi Friends,

Today, i would like to introduce one quick and very useful technique to generate a new type. Basically, Types here am referring for classes. Many a time, when you are coding, you need to feed data to some service, so rather passing the same as individual parameters, we usually prefer via model.

Let me give a brief demo on the same. Now, below am accepting few parameters from the webpage in old school style.

1st

Now, rather doing this, we can wrap the same in one class and then expose the same. So, here i’ll use the re-factoring technique to create my class as shown below.

2nd

Then, specify the parameters as shown below

3rd

 

4th

Now, in that class you can go ahead and specify these properties as shown below.

5th

So,  now when you run and check, it will produce the same thing but in a more structured pattern.

6th

That’s it for now. Till then stay tuned and happy coding.

Thanks,
Rahul