fork download
  1. using System;
  2. using static System.Console;
  3. // i will use constructor injection in here
  4. // i know i should make it in sperate files but just so i could publish on ideone and i think it doesnt need a repo in github
  5. public interface Ipayment
  6. {
  7. public string completePayement();
  8. }
  9.  
  10. class paypalpayement : Ipayment
  11. {
  12. public string completePayement()
  13. {
  14. return $"Paypal payment is successful ";
  15. }
  16. }
  17.  
  18. class creditcardpayment : Ipayment
  19. {
  20. public string completePayement()
  21. {
  22. return $"credit card payment is succsseful ";
  23.  
  24. }
  25. }
  26.  
  27. class extendedpayment : Ipayment
  28. {
  29. public string completePayement()
  30. {
  31. return $" the extended payment is successful operation ";
  32.  
  33. }
  34.  
  35. }
  36.  
  37. class pay
  38. {
  39. private readonly Ipayment ipayment;
  40.  
  41. public pay(Ipayment payemnt )
  42. {
  43. ipayment = payemnt;
  44. }
  45.  
  46. public void finishpay()
  47. {
  48. WriteLine(ipayment.completePayement());
  49. }
  50. }
  51.  
  52. public class Test
  53. {
  54. public static void Main()
  55. {
  56.  
  57.  
  58. Ipayment creditcard=new creditcardpayment();
  59. pay m1 = new pay(creditcard);
  60. m1.finishpay();
  61. creditcard = new paypalpayement();
  62. m1 = new pay(creditcard);
  63. m1.finishpay();
  64. creditcard = new extendedpayment();
  65. m1 = new pay(creditcard);
  66. m1.finishpay();
  67.  
  68. }
  69. }
Success #stdin #stdout 0.05s 28592KB
stdin
Standard input is empty
stdout
credit card payment is succsseful 
Paypal payment is successful 
 the extended payment is successful operation