Paste the same freight-rate math into a trigger, a flow action and a batch job, and the first rate change leaves three versions of it disagreeing in production. An Apex class fixes that: it is a named template, modeled on Java, that holds variables (the state) and methods (the behavior), and every other piece of Apex creates objects from it with new or calls its static methods directly.
We built one real class for a Ridgeline Supply freight quote and deployed it with a passing test class. You will see how apex classes in salesforce use constructors and this() chaining, static final constants, static versus instance members, sharing keywords