This code does not work, but hopefully you are trying to get it here. I have got a money class, which I have taken, and has extended it to include currency conversion.
Implementation for the actual conversion rate may vary in each project, so I decided to move the actual method to get a conversion rate (GetCurrencyConversionRate) into a derived class, but the code in the convert_to method The GetCurrencyConversionRate work is overridden for any implementation that takes the derived class, so I want to keep it in the original class. A. Got it? So what am I trying to do, getting an example of submissions, and be able to call. The ConvertTou () method, which will use the override GetCurrencyConversionRate, and return a new instance of SubMoney.
The problem is, I really can not really understand some concepts of polymorphism and heritage, so I'm not sure what I'm trying to do, the way I think As it is possible, what is happening now is that I end up with an exception where it has used the GetCurrencyConversionRate method instead of the derivative one, tells me that I have a Convert-To below the derived class The method needs to be transferred, but it seems that I have to repeat the code in many implementations, so surely there is a better way?
get public class currency {public currency converter right {GetCurrencyConversionRate (_regionInfo.ISOCurrencySymbol); }} Public Fixed Decimal GetCurrencyConversionRate (string isoCurrencySymbol) {new exception throw ("If you want to use it, then this method is overridden."); } Public Money Convert (String Countries) {// Convert Base USD before dividing the current amount by the exchange rate. Money money = this; Decimal conversion rate = this Currency conversion rates; Conversion into decimal USDMount = Money.Divid (some money, conversion rate). // Now convert to new currency CultureInfo cultureInfo = New CultureInfo (cultureName); Regional Information Field Info = New Area (Culture Info LCID); Conversion rate = GetCurrencyConversionRate (regionInfo.ISOCurrencySymbol); Decimal converted ammount = converted USDMount * conversion rate; Money converted currency = new money (converted amount, culture name); Refunded Money; }} Public class SubMoney {public subtotal (decimal amount, string culture name): base (zodiac, culture name) {} public fixed decimal decimals GetCurrencyConversionRate (string isoCurrencySymbol) {// it will receive conversion rate from some web or database source decimal result = New decimals (2); Return result; }}
A static method can be used only by specifying that exact class Where it has been declared. There is no way to include Virat in it.
Make money
the essence of the class so that it can be used. Summarize the GetCurrencyConversionRate method (which automatically makes it virtual). Make money
and inherit the GetCurrencyConversionRate
method:
public intangible class money { Public abstract Decimal GetCurrencyConversionRate (string isoCurrencySymbol); ...} Public Category SubMoney: Money {Public Override Decimal GetCurrencyConversionRate {string} is defined as {...}} The class, it knows about it and can use it, the actual class you make the example is derived class like subcontinent
, so the method is always implemented.
Comments
Post a Comment