【发布时间】:2021-07-09 15:42:59
【问题描述】:
我有几个相同方法的实现SetRateForMeasure:
package repartition
type Repartition interface {
Name() string
Compute(meters []models.Meter, totalsProd, totalsConso map[string]float64) []models.Meter
SetRateForMeasure(meter models.Meter, measure models.Measure, total float64) float64
}
然后,在我的代码中(在 repartition.go 中),我称之为:
rate := repartition.SetRateForMeasure(meter, measure, total)
repartition 是之前定义的接口。
问题是,当我添加此方法的新实现时,我的函数的参数可能会有所不同。
例如,静态重新分区使用仅在这种情况下使用的静态百分比。
我最终添加了参数,以便我对所有方法都有一个通用接口,但结果是有很多未使用的参数,具体取决于实现。
如果我将它添加到通用接口,它将不会用于其他定义。
我试图从我的接口定义中删除这个方法,但是现在
rate := repartition.SetRateForMeasure()
不再定义。
我应该如何组织我的代码?
【问题讨论】: