What do you call a class / method that calls only other methods?

Say I follow the principle of shared responsibility, and I have the following classes.

public class Extractor { public Container extract(List<Container> list) { ... some extraction } } public class Converter { public String convert(Container container) { ... some conversion } } 

As you can see, this is in accordance with the principle, and all class / method names report what they do. Now I have another class that has such a method.

 public class SomeClass { private Extractor extractor = new Extractor(); private Converter converter = new Converter(); private Queue queue = new Queue(); public void someMethod(List<Container> list) { Container tmp = extractor.extract(list); String result = converter.convert(tmp); queue.add(result); } } 

As you can see, "someMethod" -Method calls, converts and adds. Now my question is: what do you call such a class / method? It does not extract, convert or add, but calls them? If you name the method after its responsibility, what would it be?

+4
source share
5 answers

Well, since you seem to be adding to the queue and you are not returning anything that I would call addToQueue . The fact that you are converting + extract is implementation details that, it seems to me, need not be disclosed.

+2
source

What about processAndQueueMessage ?

Also (not applicable), you should not create (using new ) Extractor and Converter in your SomeClass , you should add them (when building or in setters) and use interfaces to them. This will simplify validation and reduce communication between implementations.

 // Assuming Converter and Extractor are interfaces to the actual implementations public class SomeClass { private final Extractor extractor ; private final Converter converter; private Queue queue = new Queue(); public SomeClass(Extractor extractor, Converter converter) { this.converter = converter; this.extractor = extractor; } public void someMethod(List<Container> list) { Container tmp = extractor.extract(list); String result = converter.convert(tmp); queue.add(result); } } 

And you create it using:

 final SomeClass myProcessor = new SomeClass(new MyExtractorImplementation(), new MyConverterImplementation()); 

(Or use a DI container like Spring or Pico )

+1
source

Sounds like some kind of builder class. You get the data in one format, convert it and then create some kind of output format. So what about "SomethingSomethingBuilder"?

I assume that someone stopped me because I forgot to provide a good name for the method. Excuse me.

Thus, this method adds incremental data to your builder class. I would call it "Add", "AddData" or "Push" (I would probably go with push because it is very similar to many standard classes).

An alternative to "Builder" could be "SomeKindOfCreator". Obviously, you would name it based on what your class actually creates.

0
source

If you want the name to be really generic, I would go with addToQueue () or populateQueue (), since getting something in this object seems to be the method point.

But in fact, at this level, I would call it the business logic that he was trying to execute, in which case the name really depends on what it is used for.


If you can't find a good name, this suggests that your procedural abstraction is rather arbitrary / artificial, and a possible hint that there might be a better way to do this. Or maybe not.

0
source

What you do is think about the compound meaning of the sequence of method calls, turn it into a short verb or verb phrase, and use it as a name. If you cannot find the short name, you can use a common / neutral name (for example, "process") or use something completely fictitious (for example, "sploddify").

0
source

Source: https://habr.com/ru/post/1381457/


All Articles