473,659 Members | 2,987 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Attribute/Base Class Naming

Hello All,
I am fairly new to creating custom attributes, and want to get a
better feel for how they should be named.

We have a class hierarchy, with a base class called "SequenceComman d".
This class has a couple static functions and an embedded class, all of
which are referenced in code like "SequenceComman d.Create()" or
"SequenceComman d.ArgumentDef". There is also a fairly rich hierarchy
of classes under it (maybe 10-15 intermediate classes and about 30
concrete/instantiable classes).

We recently created a custom attribute, which we would apply to the
concrete classes in the hierarchy that we intend to "use" (allowing
them to be used in reflection). This makes our reflection code, which
finds usable classes by name, quite a bit cleaner. Classes without
this attribute are not used, even if they are otherwise capable of
being instantiated, etc.

We want to call this custom attribute class
"SequenceComman dAttribute". The fact that you are applying this
attribute to a class implies that it is "usable", "instantiab le", or
"executable ", so I think it is slightly redundant to include these
terms in the name of the attribute class.

This approach leads to code like...

[SequenceCommand ("MY_COMMAND ")]
public class MySequenceComma nd : SequenceCommand
{
// implementation

}

There is no conflict here, but it just looks odd that you see
"SequenceComman d" in two places -- one of which is actually referring
to the SequenceCommand Attribute class.

Question: Is this bad practice?
I have found two similar classes in .NET:
System.Runtime. Remoting.Activa tion.UrlAttribu te and
System.Security Policy.Url. These are in two different namespaces, but
perhaps, with the right combination of "using" statements, they could
lead to the same syntax I am describing.

Two alternatives:
1. Change the base class to "SequenceComman dBase"
I don't like this because of the references to the embedded class
"ArgumentDe f" and the static functions. ("SequenceComma ndBase" just
does not feel right in those cases)

2. Change the attribute class to "ExecutableSequ enceCommandAttr ibute"
I don't like this because it is a little bit verbose, and the
attribute will be applied in many places.

Is there an official position on this sort of thing?
TIA for your help!
- Chris

Jun 22 '07 #1
1 1979
Chris,

I wouldn't say that it is bad practice, but perhaps you can rename the
SequenceCommand to be more reflective of what you are trying to do. For
example, "MY_COMMAND " is some sort of key, or command text, right? In that
case, you can be more specific with the attribute name, naming it something
like "SequenceComman dText" or "SequenceComman dKey". Of course, this
attribute serves double-duty, in that your framework can only use the class
if that attribute is on it.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard. caspershouse.co m

"chris.bahn s" <ch***@bahns.co mwrote in message
news:11******** **************@ n2g2000hse.goog legroups.com...
Hello All,
I am fairly new to creating custom attributes, and want to get a
better feel for how they should be named.

We have a class hierarchy, with a base class called "SequenceComman d".
This class has a couple static functions and an embedded class, all of
which are referenced in code like "SequenceComman d.Create()" or
"SequenceComman d.ArgumentDef". There is also a fairly rich hierarchy
of classes under it (maybe 10-15 intermediate classes and about 30
concrete/instantiable classes).

We recently created a custom attribute, which we would apply to the
concrete classes in the hierarchy that we intend to "use" (allowing
them to be used in reflection). This makes our reflection code, which
finds usable classes by name, quite a bit cleaner. Classes without
this attribute are not used, even if they are otherwise capable of
being instantiated, etc.

We want to call this custom attribute class
"SequenceComman dAttribute". The fact that you are applying this
attribute to a class implies that it is "usable", "instantiab le", or
"executable ", so I think it is slightly redundant to include these
terms in the name of the attribute class.

This approach leads to code like...

[SequenceCommand ("MY_COMMAND ")]
public class MySequenceComma nd : SequenceCommand
{
// implementation

}

There is no conflict here, but it just looks odd that you see
"SequenceComman d" in two places -- one of which is actually referring
to the SequenceCommand Attribute class.

Question: Is this bad practice?
I have found two similar classes in .NET:
System.Runtime. Remoting.Activa tion.UrlAttribu te and
System.Security Policy.Url. These are in two different namespaces, but
perhaps, with the right combination of "using" statements, they could
lead to the same syntax I am describing.

Two alternatives:
1. Change the base class to "SequenceComman dBase"
I don't like this because of the references to the embedded class
"ArgumentDe f" and the static functions. ("SequenceComma ndBase" just
does not feel right in those cases)

2. Change the attribute class to "ExecutableSequ enceCommandAttr ibute"
I don't like this because it is a little bit verbose, and the
attribute will be applied in many places.

Is there an official position on this sort of thing?
TIA for your help!
- Chris

Jun 22 '07 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
2028
by: Gabriel Genellina | last post by:
Hi In the following code sample, I have: - a Worker class, which could have a lot of methods and attributes. In particular, it has a 'bar' attribute. This class can be modified as needed. - a Base class (old-style) which defines a default class attribute 'bar' too. I can't modify the source code of this class. Note that Workes does not inherit from Base. - a Derived class which must inherit from Base and is a wrapper around Worker: it...
7
3654
by: svilen | last post by:
hello again. i'm now into using python instead of another language(s) for describing structures of data, including names, structure, type-checks, conversions, value-validations, metadata etc. And i have things to offer, and to request. And a lot of ideas, but who needs them.... here's an example (from type_struct.py):
2
10686
by: Greg | last post by:
Hi. I have a rather large xml document (object) that can have one or more nodes with a certain attribute throughout (at ANY depth, not at the same level necessarily). I need to find this attribute and remove the containing node (and child nodes) if it has a certain value. I'm able to find the attributes using an XmlTextReader. Once found, can someone help me get the XPath at that point? I would then use this to remove the node from...
5
1467
by: Russell Warren | last post by:
I just ran across a case which seems like an odd exception to either what I understand as the "normal" variable lookup scheme in an instance/object heirarchy, or to the rules regarding variable usage before creation. Check this out: >>> class foo(object): .... I = 1 .... def __init__(self): .... print self.__dict__ .... self.I += 1
5
3671
by: crystalattice | last post by:
I've finally figured out the basics of OOP; I've created a basic character creation class for my game and it works reasonably well. Now that I'm trying to build a subclass that has methods to determine the rank of a character but I keep getting errors. I want to "redefine" some attributes from the base class so I can use them to help determine the rank. However, I get the error that my base class doesn't have the dictionary that...
6
2829
by: noel.hunt | last post by:
I have a base class, PadRcv, with virtual functions. User code will derive from this class and possibly supply it's own functions to override the base class virtual functions. How can I test that a user-defined class has overriden the virtual function in the base class? I have code like this which compiles with gcc 2.95.4: Attrib Implicits(PadRcv *obj){ Attrib accum = 0;
0
1126
by: chris.bahns | last post by:
Hello All, I am fairly new to creating custom attributes, and want to get a better feel for how they should be named. We have a class hierarchy, with a base class called "SequenceCommand". This class has a couple static functions and an embedded class, all of which are referenced in code like "SequenceCommand.Create()" or "SequenceCommand.ArgumentDef". There is also a fairly rich hierarchy of classes under it (maybe 10-15 intermediate...
1
3397
by: mrstephengross | last post by:
I've got a Base class with an attribute "foo" (of type Foo), and a Derived class (derived from Base). In Derived's constructor, I try to refer to Base.foo, but python complains: AttributeError: class Base has no attribute 'foo' Any ideas? (code below) === CODE === #!/usr/bin/python
1
1363
by: Florian Paulus | last post by:
Hi group, i'm wondering how to assign an attribute to a field that a class inherited from a base class. Say base class has a field protected string message, so in the derived class i want to assign an attribute to it, i don't know how. i don't want to override the base class field, just add an attribute. and i can't add it in the base class cause the different subclasses use
0
8428
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8335
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
8528
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
5649
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4175
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4335
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2752
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1976
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1737
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.