我应该将费用/折扣表到Order类或让他们成为itemlines [英] Should I incorporate list of fees/discounts into an order class or have them be itemlines

查看:80
本文介绍了我应该将费用/折扣表到Order类或让他们成为itemlines的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我没有其他的开发人员求教或者你觉得呢 - 我想的这个的,所以请,如果你有时间,有一个读,让我知道你在想什么

I have no other developers to ask for advice or "what do you think - I'm thinking this" so please, if you have time, have a read and let me know what you think.

它更容易表现出比形容,但应用程序基本上是想用3个主要部分销售点应用程序:项目,的OrderItems和订单

It's easier to show than describe, but the app is essentially like a point of sale app with 3 major parts: Items, OrderItems and the Order.

该项目类是数据,因为它来自于数据存储。

The item class is the data as it comes from the datastore.

public class Item 
    : IComparable<OrderItem>, IEquatable<OrderItem>
{
    public Int32 ID { get; set; }
    public String Description { get; set; }
    public decimal Cost { get; set; }

    public Item(Int32 id, String description, decimal cost) 
    { 
        ID = id; 
        Description = description; 
        Cost = cost;
    }
    // Extraneous Detail Omitted
}



订单。项目类是为了在项目上线

The order item class is an item line on an order.

public class OrderItem 
    : Item, IBillableItem, IComparable<OrderItem>, IEquatable<OrderItem>
{
    // IBillableItem members
    public Boolean IsTaxed { get; set; } 
    public decimal ExtendedCost { get { return Cost * Quantity; } } 

    public Int32 Quantity { get; set; }

    public OrderItem (Item i, Int32 quantity) 
        : base(i.ID, i.Description, i.Cost) 
    {
        Quantity = quantity;

        IsTaxed = false;
    }
    // Extraneous Detail Omitted
}

目前,当你加费或折扣的订单很简单:

Currently when you add fees or discounts to an order it's as simple as:

Order order = new Order();
// Fee
order.Add(new OrderItem(new Item("Admin Fee", 20), 1));

// Discount
order.Add(new OrderItem(new Item("Today's Special", -5), 1));



我喜欢它,这是有道理的,而且顺序遍历的项目继承的基类列表,计算相应税费,并允许其他订单类型的文件(其中有2)从该计算所有这一切无需重新implimenting任何的基类继承。如果订单类型的文档没有折扣,这是因为只是不添加一个简单 - $值OrderItem的

I like it, it makes sense and a base class that Order inherits from iterates through the items in the list, calculates appropriate taxes, and allows for other Order-type documents (of which there are 2) to inherit from the base class that calculates all of this without re-implimenting anything. If an order-type document doesn't have discounts, it's as easy as just not adding a -$ value OrderItem.

这是我在被显示的唯一问题此数据。形式(S),这继续有这里出售的项目(即不收费/折扣)应显示网格。同样,也有某些费用和一定的折扣文本框。我非常希望数据绑定的UI元素的字段在这个类,以便它的用户更容易(和我)。

The only problem that I'm having is displaying this data. The form(s) that this goes on has a grid where the Sale items (ie. not fees/discounts) should be displayed. Likewise there are textboxes for certain fees and certain discounts. I would very much like to databind those ui elements to the fields in this class so that it's easier on the user (and me).

我的想法

有2个接口:IHasFees,IHasDiscounts并有秩序加以实施;两者都将有名单中的单个成员。 。这样一来,我可以访问只售项目中,只有费也只有折扣(并将其绑定到控件如果需要的话)

Have 2 interfaces: IHasFees, IHasDiscounts and have Order implement them; both of which would have a single member of List. That way, I could access only Sale items, only Fees and only Discounts (and bind them to controls if need be).

我不喜欢它的内容:
- 现在我有3个不同的添加/删除类方法(的AddItem / AddFee / AddDiscount /删除...)
- 我重复为所有的人都是(triplicating?)功能简单地列出了相同类型的物品的,只是每个列表都有不同的意义。

What I don't like about it: - Now I've got 3 different add/remove method for the class (AddItem/AddFee/AddDiscount/Remove...) - I'm duplicating (triplicating?) functionality as all of them are simply lists of the same type of item, just that each list has a different meaning.

我在正确的道路上?我怀疑这是一个解决问题的大多数人(考虑到这种类型的软件是很常见的)。

Am I on the right path? I suspect that this is a solved problem to most people (considering that this type of software is very common).

推荐答案

我LL点你在一个ALT.net播客我听了不久前说过一句话罗布·康纳利(我不是一个ALT.net倡导者,但推理似乎声音):

I'll point you to a remark by Rob Connery on an ALT.net podcast I listened to not long ago (I'm not an ALT.net advocate, but the reasoning seemed sound):

什么是有意义的业务用户(如果您有任何周围的人)。

What does make sense to a "business user" (if you have any of those around).

作为一个程序员,你会想要因素在项目,收费,优惠等,因为它们具有相似的属性和行为。

As a programmer, you're gonna want to factor in Item, Fee, Discount etc, because they have similar attributes and behaviors.

但是,他们可能是在模型方面的两个完全不同的概念。而有人会来在以后的时间,说:但是这是没有意义的,它们是独立的事情,我需要对他们单独报告,我需要这个特定的规则适用于在这种情况下折扣。

BUT, they might be two totally separate concepts in terms of the model. And someone is gonna come at a later time, saying "but this makes no sense, they are separate things, I need to report on them separately and I need to apply this specific rule to discounts in that case".

干并不意味着限制你的模型,并通过继承或类似的东西融通行为时,你应该保持在视线。

DRY does not mean limiting your model, and you should keep that in sight when factoring behavior via inheritance or anything like that.

这是在这种情况下使用的具体的例子是,购物车。程序员的自然的想法是在未提交状态下使用的命令。它是有道理的,因为它们看起来一模一样。
除它们不是。这是没有意义的客户,因为他们是两个不同的概念,它只是使设计不太清楚。

The specific example that was used in that case was that of the shopping cart. The programmer's natural idea was to use an order in an uncommited state. And it makes sense, because they look exactly the same. Except that they are not. It makes no sense to the client, because they are two separate concept, and it just make the design less clear.

这是惯例,口味和意见的问题,虽然,所以不要盲从发布在网站上的建议:)

It is a matter of practices, taste and opinion though, so don't blindly follow advice posted on a web site :)

和您的具体问题,我与用途的项目,收费标准,行项目折扣工作体系(该项目的一个属性)和订单在全球的折扣(虽然它不是一个命令,它的POS收据,但它并没有真正在这种情况下问题)。

And to your specific problem, the system I work with uses items, fees, line-item discount (a property of the item) and a global discount on the order (though it's not an order, it's POS receipt but it does not really matter in that case).

我想原因在于,这些概念的背后,项目是清点件具体事例,它们影响库存数量,它们是枚举和可量化的。

I guess the reason is that, behind those concepts, Items are specific instances of inventoried pieces, they impact stock quantities, they are enumerable and quantifiable.

费用都没有。他们不同意大多数属性。

Fees are not. They do not share most of the attributes.

它可能不是你的情况关系,因为您的域似乎远不止于此有限的,但你可能想保留这些问题记在心里。

It might not matter in your case, because your domain seems much more limited than that, but you might want to keep those issues in mind.

这篇关于我应该将费用/折扣表到Order类或让他们成为itemlines的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆