Thread overview
Bir interface objeden türetilmiş objenin bütün fonksiyonları uygulaması kuralı
Mar 17, 2019
kerdemdemir
Mar 18, 2019
kerdemdemir
March 17, 2019
interface ICurrencyStrategyTuner
{
	string GetExtraCsvString();
	void   StartCreatingData( Currency data);
	Strategies GetStrat();
	double GetSuggestedPrice();
	void   UpdatePriceWithFallBack( ref double price );
	bool  IsBargain();
	ref double GetBargainWall();
	double GetInvestRatio();
	double GetCutRatio();
	int    GetLevel();
	int    GetMaxLevel();
}

class BaseCurrencyStrategyTuner : ICurrencyStrategyTuner
{
	int    GetLevel()
	{
		return curveLevel;
	}

	int    GetMaxLevel()
	{
		return maxLevel;
	}
	int maxLevel = 1;
	int curveLevel = 0;
	double fallBackWall = 0.0;
}

İlk başta elimde sadece ICurrencyStrategyTuner vardi sonra sadece

	int    GetLevel();
	int    GetMaxLevel();
	int maxLevel = 1;
	int curveLevel = 0;

eklemek istedim. Bunun için ara bir sınıf oluşturdum yukardaki gibi.

Derleyici şöyle bir hata verdi:

source/Currency/CurrencyAnalyzeTuner.d(26,1): Error: class Currencies.CurrencyAnalyzeTuner.BaseCurrencyStrategyTuner interface function 'string GetExtraCsvString()' is not implemented
......
source/Currency/CurrencyAnalyzeTuner.d(26,1): Error: class Currencies.CurrencyAnalyzeTuner.BaseCurrencyStrategyTuner interface function 'double GetCutRatio()' is not implemented

Sonra şu notu gördüm şu linkte : "https://dlang.org/spec/interface.html"
Alıntı:

>

"A reimplemented interface must implement all the interface functions, it does not inherit them from a super class"

C++'da bile böyle bir sormala yok tabi BaseCurrencyStrategyTuner 'i örneklemek istersem C++ kızar ama örneklemezsem bildiğim kadarıyla kullanabilirim. D örnekleme yapmasam bile hata veriyor.

Acaba ben mi birşeyleri yanlış yapıyorum.

Erdemdem

--
[ Bu gönderi, http://ddili.org/forum'dan dönüştürülmüştür. ]

March 18, 2019

Süpersin abi sağol

--
[ Bu gönderi, http://ddili.org/forum'dan dönüştürülmüştür. ]

March 18, 2019

Kısıtlama mantıklı çünkü 'class' o arayüzü desteklediği sözünü veriyor. Çözüm 'abstract' anahtar sözcüğünü eklemek: 'class' -> 'abstract class'. :)

Ali

--
[ Bu gönderi, http://ddili.org/forum'dan dönüştürülmüştür. ]