I'm reading Robert C. Martins book Clean Code. He writes about a convention not using verbs in class names.
The project I'm currently working on we need to validate and process some xml, so I created something like this
public class XmlProcesser
{
public XmlProcesser(string filePathAndName)
{
}
public bool Validate()
{
}
}
But Uncle Bobs recommendation is not to use "Processor" in the class name.
But what should I call it? Xml is no good, because I'm using the .net class xml a lot in the code. I thought about XmlHandler but I guess that is worse than Processor since "handler" is something else for a programmer.
How do you do? Do you use verbs in your class names?
Naming is important. Heck, T.S. Eliot and Andrew Lloyd Webber made fortunes from The Naming of Cats. But Martins' point isn't about not using verbs - it's about object-oriented thinking. Classes are patterns for instantiating objects. Objects are things. Are similar things better described by their behaviors or by their names?
Am I a carnivore? Yup. But I also write programs. Am I a programmer? Yup. But I also voted for Obama. Am I an Obama supporter? Yup. But ... In the end, I am a person. More correctly, I am an instance of the class[1] HomoSapiensSapiens
. And HomoSapiensSapiens
has many, many, MANY methods, all of which have verb-like names to them. Like HomoSapiensSapiens.EatBacon()
. Like HomoSapiensSapiens.WriteGoodCode()
. Like HomoSapiensSapiens.VoteDemocratic()
. etc.
Martin's big point is that if your classes are best named like verbs, you're thinking about your classes all wrong.
[1] "class" in the OO meaning, not the Kingdom/Phylum/Class biological meaning.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With