Is there a naming convention for a method that should set properties of the passed object
I am writing a method that will set the properties of an object passed as a parameter. The method takes one type interface parameter, and the return type of the method is the same interface. I was wondering if there is some naming convention for methods like this. I was thinking about something like:
FillInInterfaceTypeData strong> or InitInterfaceTypeData strong>, but both sounds awkward to me. What do you think?
a source to share
I guess it depends on what you are filling with objects and why?
Are you setting the default values? In this case, something like InitialiseTypeData or DefaultTypeData might make sense.
Perhaps you have cleared your values? It is possible that the state of the objects is moving to another. In this case, something like DeactivateBankAccount or MakeUserMarried or whatever is done with the objects.
Beware of Code Smells Often (not always, of course) you will find that if you have difficulty assigning a name to a method, this indicates that there is something wrong with the design, which can lead to difficulties later.
There may be other things in the design that you should consider.
For example, if this method sets default values, isn't that what should happen in the constructor of the class?
If an interface represents multiple class types that all need the same values, perhaps each of these classes can be split into 1 class that represents the same between each of these classes and another class that represents the difference.
t.
interface IA
{
int a;
int b;
}
class X : IA
{
int a;
int b;
int c:
}
class Y : IA
{
int a;
int b;
int d:
}
can be reorganized into
class A
{
int a;
int b;
}
class X
{
A a;
int c:
}
class Y
{
A a;
int d:
}
Then the constructor of class A can set its default values. You no longer need to put in any effort to come up with a good function name. You also get a more orthogonal system that is easier to test and handle changes.
Obviously this is probably not really your situation, I'm just stressing how when you are trying to find a good name because your design needs improvement!
a source to share