Reputation: 1076
I'm sure this has been asked before, but I'm having trouble finding any relevant answers - probably because the generic nature of the terms I'm using.
I have a class - let's call it Foo
. Now a given Foo
has a variety of properties that define it's nature. For the sake of argument, let's call them Name
, Inactive
and Notes
. There can also be many varieties of Foo
, which are each a FooType
, for lack of a better word.
So, we have the following class definitions:
public class FooType
{
public byte Id { get; set; }
public string Name { get; set; }
public bool Inactive { get; set; }
public string Notes { get; set; }
}
public class Foo
{
public Guid Id { get; set; }
public FooType TypeOfFoo { get; set; }
public string Name { get; set; }
public bool Inactive { get; set; }
public string Notes { get; set; }
}
Not exactly an ideal situation, I know. Sadly, the Inactive
and Notes
fields on FooType
are a must, so I can't use an enum
as I would like. My quandary, then, is that I'm having trouble figuring out a reasonably descriptive name for TypeofFoo
and FooType
. Calling them TypeofFoo
and FooType
is ugly and prone to confusion in the future, so I'm looking for alternatives.
Is there any sort of naming convention that covers this?
Upvotes: 0
Views: 692
Reputation: 152624
No, there's no naming convention. In fact, the .NET Framework itself does not avoid using properties that have the same name as their type and even suggest it in some older guidelines:
It's not a fool-proof solution, and may cause confusion in certain edge cases like calling static members, but it's not so bad that there's reason to avoid it categorically.
Upvotes: 3
Reputation: 346
I would try to use polymophy to subclass Foo
and use a factory with an enumeration FooType
to create the objects. Your subclasses should override the general methods to add specific behavior.
But I think the context is important to choose the right pattern. Just using a special naming is confusing in my opinion and doesn't represent your intend of the classes.
Upvotes: 0