I have several classes like(debitrequest.ce , pinchangerequest.cs and inquieryrequest.cs ......) but most of the code in all these classes are same expect few naming changes. Now my requirement is i dont want these many classes with common functionality.
I want to built a single class to which i want to pass type like (debitrequest or pinchangerequest) and it should return me the object of type which i have passed. is this possible ... ?
class myfunctions
{
public somereturntype debitrequest()
{
// do something
}
public somereturntype pinchangerequest()
{
// do something
}
public somereturntype inquiryrequest()
{
// do something
}
}
One class; not quite sure if this is what your after. You're possibly still repeating blocks of code. In which case you can split them of into a number of private methods in the same class.
Only Robinson Crusoe had everything done by Friday.
Use Abstract design pattern to achieve, make common functionality in abstract class like make more generalized class, then inherit from to create more special class like child class,
Now SOLID principle are more power full, please go through SOLID.
Member
3 Points
13 Posts
Creating the reusable class
Sep 03, 2014 09:13 AM|srividya_sv|LINK
Hi All,
I have several classes like(debitrequest.ce , pinchangerequest.cs and inquieryrequest.cs ......) but most of the code in all these classes are same expect few naming changes. Now my requirement is i dont want these many classes with common functionality. I want to built a single class to which i want to pass type like (debitrequest or pinchangerequest) and it should return me the object of type which i have passed. is this possible ... ?
Participant
1465 Points
449 Posts
Re: Creating the reusable class
Sep 03, 2014 10:34 AM|ankit.sri|LINK
yes very much possible, try using Request/Response design pattern.
Contributor
3054 Points
1018 Posts
Re: Creating the reusable class
Sep 03, 2014 12:28 PM|wim sturkenboom|LINK
from the head
One class; not quite sure if this is what your after. You're possibly still repeating blocks of code. In which case you can split them of into a number of private methods in the same class.
Member
583 Points
265 Posts
Re: Creating the reusable class
Sep 05, 2014 01:52 AM|jayakumarvinayagam|LINK
Hi,
Use Abstract design pattern to achieve, make common functionality in abstract class like make more generalized class, then inherit from to create more special class like child class,
Now SOLID principle are more power full, please go through SOLID.
Kind,
Jai