locked
Polymorphism in Ecommerce RRS feed

  • Question

  • User2017673925 posted

    Can you give me an scenario example how you have used polymorphism in your project.  With new and override keyword.

    Please give me an example from a finance domain/ecommerce domain.  I am looking from a UML Model Perspective.

     

    Thanks.

    Thursday, June 17, 2010 1:41 AM

Answers

  • User-1399914977 posted

    Well polymorphism means in many forms. The best example would be function overloading :

    Say you have two functions with same name :

    ex:-  public bool ProcessPayment(decimal amt, string cardnumber) 

    ex:-  public bool ProcessPayment(decimal amt, int cardId)

    Here we have done function overloading (i.e. same function name but different input params).

    Another example :

    Lets say you have an abstract method ProcessAmount in your base class

    Now you can ovverride the same in derived class and implement the same in different forms as per your need.

    public abstract class XYZClass
    {
      public abstract bool ProcessPayment();
     
    }
    
    
    public class SQLDerivedXYZ : XYZClass
    {
      public ovverride bool ProcessPayment()
     {
         //implement logic to update or do somethign with sql server db
     }
    
    public ovverride bool ProcessPayment(string cardnumber, decimal amt)
     {
         //implement logic to update or do somethign with sql server db
     }
    
    }
    
    
    Hope this gives you an idea.
    


     

     

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, June 17, 2010 2:30 AM