- Allows to add methods to classes of different types without much altering of those classes.
- You can make completely different methods depending on the class used.
- Allows you to define external classes that can exten other classes without majorly editing them
we will be using
shared_ptr
for automatic memory management
In this example we will implementing different types of credit cards and calculate the cash back you get according to the offers from different credit cards
Amount of Cashback you get with different credit cards :
Offers | Gold | Silver | Bronze |
---|---|---|---|
Gas | 10% | 2% | 5% |
Food | 20% | 3% | 10% |
Hotel | 10% | 2% | 3% |
Other | 1% | 5% | 20% |