What Is Convention Over Configuration?

Convention over configuration, also known as programming by convention, is a software design paradigm designed to reduce the number of decisions a software developer needs to make and gain simple benefits without losing flexibility.

The essence is that developers only need to specify the non-conforming parts of the application. For example, if there is a class named Sale in the model, the corresponding table in the database will be named sales by default. Only when you deviate from this convention, such as naming the table "products_sold", you need to write the configuration about this name.
If the conventions of the tools you use match your expectations, you can omit configuration; otherwise, you can configure to achieve the way you expect. [1]
A poorly designed framework usually requires multiple configuration files, each with many settings. These configuration files provide information for each item, describing everything from URLs to mapping classes to database tables. A large number of configuration files with too many parameters is usually an indicator of excessively complex application design (bad code smell)
For example, in well-known Java
Many new frameworks use a convention over configuration approach, including:
Java annotations, also known as Java annotations , are special syntax metadata that support the addition of source code from the Java language version 5.0.
Classes, methods, variables, parameters, and packages in the Java language can be marked. Unlike Javadoc, Java annotations can obtain annotation content through reflection. When the compiler generates the class file, the annotations can be embedded in the bytecode. The Java virtual machine can retain the annotation content, and the annotation content can be obtained at runtime. Of course it also supports custom Java annotations. [2]

IN OTHER LANGUAGES

Was this article helpful? Thanks for the feedback Thanks for the feedback

How can we help? How can we help?