In the most lenient standards, as long as the code is not logic errors, no serious performance issues, there is no problem, but I know that he can’t ask these, but can ask code have the possibility of further optimization, I think he made clear stratification, the code to extract the base class, using the template pattern, on the whole is good.

The question is, what is good code?

Faced with this problem, most programmers may first think of: high cohesion, low coupling, high efficiency, maintenance, easy to expand. This is true, but only true nonsense, because for most IT practitioners (especially those who are new to the industry and lack sufficient knowledge and experience), there is no specific standard to measure.

Regardless of the framework and technical details, from a purely coding perspective, in my opinion:

Object – oriented programming is about abstraction.

The first level of abstraction is the class.

Starting from the actual business needs, the things in the real world are abstracted into classes. Through the mutual calls between classes and objects, the business needs are completed. This is the most basic abstraction ability of object-oriented programming.

The second level of abstraction is the base class.

Discover commonness between classes, extract base class, abstract class, base class is responsible for dealing with common logic, subclass is responsible for dealing with individual logic, so as to realize the reuse of code, logic is clearer, code is easier to maintain.

The next level of abstraction is the interface.

An interface simply defines a set of specification standards without any implementation logic, and therefore has a broader scope than an abstract class. The “dependency inversion principle” in object-oriented development principles is simply to program to interfaces.

A higher level of abstraction is generics.

Why put a generic in a level higher than the base class and interface, because the base classes and interfaces, is the successor to the single type of abstract, and generic, is the coordinate for multiple types of abstract, generics is not only to the type of abstract, and abstract out of the interaction behavior between multiple types and the correct use of generics, can make the code more refined, more rigorous logic specification.

Well, the above four levels are also simple to rank the code, and see which level of your code is in.

Afterword.

Of course, not all code needs to extract base classes and define interfaces; everything has a scope.

The above point of view on abstraction, it is their own years engaged in software development a little understanding, I hope to help you.

More widely accepted standards for distinguishing good code can be referred to as “object-oriented development principles”, because there are too many articles on this topic, not to expand here, interested friends can search by themselves.

Note: Follow the author’s wechat official account to learn more about distributed architecture, micro services, Netty, MySQL, Spring, performance optimization, etc. Public account: Java Big Snail