我有以下情况,我有不同类型的销售算法来计算销售价格.FixedSaleStrategy不需要basePrice参数,而所有其他策略实现都需要它.有没有一种避免这种冗余参数的好方法?
public abstract class SalesStrategy
{
public abstract double GetPrice(double basePrice, double saleAmount);
}
public class AmountOffSale : SalesStrategy
{
public override double GetPrice(double basePrice, double salesAmount)
{
return basePrice - salesAmount;
}
}
public class FixedPriceSale : SalesStrategy
{
public override double GetPrice(double basePrice, double salesAmount)
{
return salesAmount;
}
}
Run Code Online (Sandbox Code Playgroud) 我将python google visual api安装到我的virtualenv中
pip install -U -f http://code.google.com/p/google-visualization-python/ gviz-api-py
Run Code Online (Sandbox Code Playgroud)
我需要在pip requirements.txt文件中放入什么以便Heroku可以下载并安装它?
在这个例子中,选项2的优缺点是什么?
选项1(继承):
public class SalesList : List<Sales>
{
//methods that add extra behavior List<Sales>
}
Run Code Online (Sandbox Code Playgroud)
备选案文2(组成):
public class SalesList
{
private List<Sales> _list;
//methods that add extra behavior to List<Sales>
}
Run Code Online (Sandbox Code Playgroud) 在以下场景中,与下面的函数发生HashCode冲突的可能性有多大.
假设我们有1000万个对象.
int[] key=new int[4];
public override int GetHashCode()
{
// Use large prime multiples to create a unique hash key
// Create the hash offsets using a "even powers of 2 minus 1" method, which gives
// primes most of the time.
int hashKey = 0;
hashKey += 2047 * key[0];
hashKey += 8191 * key[1];
hashKey += 32767 * key[2];
hashKey += 131071 * key[3];
return hashKey; …Run Code Online (Sandbox Code Playgroud) 我们有一个64位C#/.Net3.0应用程序,运行在64位Windows服务器上.应用程序可能会不时使用大量可用内存.在某些情况下,应用程序停止分配额外的内存并显着减慢速度(慢500倍).当我从任务管理器检查内存时,使用的内存量几乎没有变化.应用程序继续运行非常缓慢,并且永远不会出现内存不足异常.有任何想法吗?如果需要更多数据,请与我们联系.
考虑具有许多产品的生产计划应用程序.每个产品都有一个InventoryControlType上键入的InventoryControl对象列表.根据我们为生产计划运行的算法,我们需要访问给定产品的不同类型的InventoryControl对象.这很好用.但是,今天我需要在InventoryControl中引入一个包含InventoryControlType的字段,因为我们的算法深入了解InventoryControlType.
但是,我觉得我觉得我做错了,因为看起来我正在重复数据.
这个设计看起来不错吗?有什么改进的想法吗?
class Product{
Dictionary<InventoryControlType, InventoryControl> InventoryControls;
GetInventoryControl(InventoryControlType type){
return InventoryControls[type];
}
}
class InventoryControl{
InventoryControlType controlType;
float limit;
float cost;
...
CalculateCost(){...}
GetConstraint(){...}
}
Run Code Online (Sandbox Code Playgroud) 我有一个叫做的课PriceStep.我PriceStep在一个名为的类中保留了一个对象列表PriceStepSearchSpace.现在我需要PriceStepSearchSpace为不同的产品提供不同的对象,我需要将它们保存在某种字典中.我打电话给这个新班级PriceStepSearchSpaceRepository.
你能想到更简单/更短的名字吗?
我有以下课程
public class DateRange
{
private DateTime startDate;
private DateTime endDate;
public override bool Equals(object obj)
{
DateRange other = (DateRange)obj;
if (startDate != other.startDate)
return false;
if (endDate != other.endDate)
return false;
return true;
}
...
}
Run Code Online (Sandbox Code Playgroud)
我需要在一个使用DateRange键入的字典中存储一些值,如:
Dictionary<DateRange, double> tddList;
Run Code Online (Sandbox Code Playgroud)
我应该如何覆盖类的GetHashCode()方法DateRange?
我需要计算一组文件的加权平均值.每个文档在单独的字段中包含权重和值.这是一个例子:我有两个代表销售交易的文件.
{
quantity : 3,
price : 2
}
{
quantity : 9,
price : 6
}
Run Code Online (Sandbox Code Playgroud)
我想找到这两笔交易的平均价格.这是加权平均值,其中权重是数量,价值是价格.这可以通过计算得出
AveragePrice = (3 * 2 + 9 * 6 ) / (3 + 9).
如何使用聚合框架执行此计算?
c# ×5
oop ×4
dictionary ×2
.net ×1
composition ×1
enums ×1
gethashcode ×1
hashcode ×1
heroku ×1
inheritance ×1
mongodb ×1
naming ×1
performance ×1
pip ×1
python ×1