tags:

views:

139

answers:

4

I have a field that indicates whether someone wars a commission or a fee.

In sql its going to be a bit field.

How should I name it?

+12  A: 

You might want to use an enum instead of a bool.

public enum Payment
{
    Commission = 0,
    Fee = 1
}

You can then cast it to an integer when necessary.

class Thing
{
    Payment ThingPayment { get; set; }
}

var thing = new Thing();
thing.ThingPayment = Payment.Fee;

int bitValue = (int)thing.ThingPayment;
Daniel Earwicker
Doesn't that seem like an incredible amount of code for someone to maintain, just for a bit field? Sure you can do it this way, but this desimplifies it.
le dorfier
System.Boolean doesn't use a bit field for its booleans in .NET. If the size of the enum matters, have it inherit from a different base type like: `public enum Payment : byte`...
Robert Davis
@le dorfier - No. The enum declaration is the only extra bit of code, and it is pure declaration with nothing to "maintain". When are you going to fix a bug in it? A type declaration is declared once but used, referred to, benefited from, thousands of time. Each time the coder has to assign to a `Payment` field, they will get intellisense giving them two human-readable options, instead of `1` versus `0` or `true` versus `false`, and have to guess/remember which means which.
Daniel Earwicker
Also there seems to be some confusion: the OP says that the value will be represented by a bit in SQL. That is a persistence decision. It doesn't restrict how helpful you can make your in-memory object model. So make it as helpful and clear as possible.
Daniel Earwicker
+1  A: 

My 2 rappen, I would have "IsFee" with an extended property to explain it more.

However, at the risk of YAGNI, would have have other types? Such as "retrocession" or "holding fee" as opposed to "payment fee". In which case, a tinyint lookup to another table in SQL.

And as mentioned, a c# enumeration to make things easier.

gbn
+2  A: 

The simplest thing would be to call it IsCommission (or IsFee). In C# boolean properties should generally start with 'Is' or 'Has' unless the name already implies the boolean nature. If there is a possibility of other values being added to the equation later, seriously consider making it an enumeration now. In that case, you might call it CompensationMethod, but there are quite a lot of good possible names there. If you decide to stick with boolean, which might be a good idea if your database field will remain boolean, you could expose the converse of your property like this:

protected bool isCommission
public bool IsCommission
{
get { return isCommission; }
set { isCommission = value; }
}
public bool IsFee
{
get { return !isCommission; }
set { isCommission = !value; }
}
Eric Mickelsen
If you're going to lock yourself into a bit-field then the name should plainly reflect the datatype. Using an enumeration or other type just creates a logical design conflict.
le dorfier
+1  A: 

I would hesitate to use a bit for this. You have a one-to-many relationship going which by coincidence has two possible values. But there could be more relationship values in the future. Somebody might work for free, or require a fee and a commission, or a flat fee if the amount in question is less than a certain fixed amount.

Instead, use a relational table to hold the values. You will give your design more flexibility in the end. You also obviate the need to store any constants in your code.

roufamatic