What Name for This Method?

Table of Contents

What Name for This Method?

public class OptionsAwareObject {  
    private Options options;  
      
    public void updateOptions(String fontName, int fontSize) {  
       options.setFontName(fontName);  
       options.setFontSize(fontSize);  
    }  
}  
   
class Options {  
    private int foregroundColor;  
    private int backgroundColor;  
    private String fontName;  
    private int fontSize;  
    // ...
}

Is updateOptions a good name for this method? Of course not! updateOptions is a general name that suggests a comprehensive update of options. Meanwhile, we are only updating font-related information. The responsibility of the method is thus the change of font-related options. A better name would be:

public void updateFontOptions(String fontName, int fontSize) {  //...

(Text translated and moved from original old blog automatically by AI. May contain inaccuracies.)

Related Posts

Clean Code

The Importance of Clean Code

There are ongoing philosophical discussions on whether clean code matters and if it is worth investing time to read it. I won’t engage directly in this debate. Instead, a small example should suffice:

Read More

The Key to Time Management

There are several topics that constantly come to my mind and, with each new discovery, I reach a new level of understanding. One such topic is “time management.”

Read More

Technical Leader Worries: To Be a Tech Expert or Not to Be

The majority of IT leaders are promoted IT specialists. Many times, this happens surprisingly, and we are usually not well prepared for this change. We love our tech job—programming—and suddenly someone wants to take it from us. Of course, we are free people and can say “NO,” but it doesn’t happen too often. Becoming a leader may be the next real step in our career, a new opportunity to learn something completely different.

Read More