This is the third day of my participation in the August More Text Challenge

What should a class look like

Top-down principles

The class starts with a list of variables, in the order public static, private static, and private entity variables.

The public method is followed by the private method that the public method calls.

A single power and responsibility

A class should have only one responsibility, that is, only one reason to change. How to determine if a class has too many responsibilities can be used:

  1. Whether the class can be named explicitly
  2. Whether there are too many entity variables in the class

Good classes should be cohesive enough to break large classes into smaller cohesive classes to prevent excessive coupling.

The open closed principle

A good class should conform to the open and closed principle. For the business with complex logic, the design pattern should be reasonably used to design the class, so that the system can adapt to continuous modification. Classes should therefore be organized for modification (system-functional-level modification), with minimal modification of existing classes as new functionality is added, and new features are added by extending the system.

System-level neatness

The system level is a higher level of abstraction where the focus is on the framework for functional implementation rather than on specific coding specifications. The system should be clean and free from intrusive architecture.

Separate construction and use

Separating the construction and use of the system leaves the application ignorant of the construction process and just expecting everything to work. Building objects in the beginning creates complex dependencies, and the need to determine whether the right objects are being created in each environment adds complexity to unit testing, so you need to separate construction from usage. Object construction is usually implemented using dependency injection or factories, where the application decides when to create the object, but the details are isolated from the application. Dependency injection is an important feature provided by Spring injection. When we need an object, we just inject it and use it. The construction process is provided by Spring.

section

AOP avoids the problem of tight coupling by allowing you to add new functionality without breaking existing code. Simple cases can be made using Java proxies to implement a function in the field at the aspect level, but the complexity and amount of code of the proxy makes it difficult to clean the code, and the proxy cannot specify execution points system-wide, so an AOP framework is still required to implement it.