Question Naming convention with only capitalized letters

bondra

Well-known member
Joined
Oct 24, 2020
Messages
77
Programming Experience
Beginner
I've gotten following part for an UML-diagram. I don't like the way the method CAT is written however with only capitalized letters. I understand why since it will conflict with the name of the class otherwise.
But is there some standard naming convention for this scenario?

The class from the UML-diagram:
CAT
+ Cat (in name: string, in age : int)
    +hungry_animal()
    +ToString() : string

Wouldn't this look better using output or something else, what now that might be?
C#:
CAT
+ CatOutput (in name: string, in age : int)
    +hungry_animal()
    +ToString() : string
 
'CAT' there is not a method. It looks to be a class name. In C (and old C++), the convention used to be all capitals for type names. In C#, the type names are always Pascal case.

UML is not text. It's graphical. So that class would actually look like this:
Screenshot_1.png


I suspect that someone has invented their own version of Textual UML to add to the list of existing ones. Also normally, UML doesn't bother listing constructors in the methods section (eg. your Cat() or CatOutputp()) unless there is a specific idea that needs to be communicated (e.g. not all attributes are initialized from parameters to the constructor).

Speaking of naming conventions, in C# class names and methods are always Pascal case (like 'Cat' and 'ToString()'). Snake case is never used in C#. So that 'hungry_animal()' should really named 'HungryAnimal()'.

And general object oriented naming conventions recommend that class methods be verbs. 'HungryAnimal' comes across more like an adjective. A more appropriate method name would be something like 'InduceHunger()' or 'IncreaseHunger()'.
 
Thanks a lot! I was on the right track regarding the HungryAnimal convention which I'd already written.
The main question makes sense also when you say that. I couldn't get my head around this and was thinking about some kind of constructor as well. But now I got it!

Should the instance names be private? Or is internal the deepest protected level an inheriting object can go?

Thanks once again!
 
The rule of thumb is to keep things private until you can't keep it private anymore.
 
The rule of thumb is to keep things private until you can't keep it private anymore.
Do you have something you want to tell us? ;)
 
It's a corollary of the C++ rule: Don't let friends play with your privates. (Unless they are friends with benefits.)
 
Circumstantially. Its ok to allow friends to play with your privates, providing the situation is favourable.
So it's not OK if you're not circumstanted?

@bondra, I apologise for the irrelevant posts but some opportunities are too good to pass up.
 
Last edited:
Back
Top Bottom