locked
Creating the reusable class RRS feed

  • Question

  • User424174089 posted

    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 ... ?

    Wednesday, September 3, 2014 9:13 AM

Answers

  • User842257015 posted

    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  

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, September 5, 2014 1:52 AM

All replies

  • User-425639139 posted

    yes very much possible, try using Request/Response design pattern.

    Wednesday, September 3, 2014 10:34 AM
  • User1428246847 posted

    from the head

    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.

    Wednesday, September 3, 2014 12:28 PM
  • User842257015 posted

    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  

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, September 5, 2014 1:52 AM