Convention over Configuration
Encyclopedia
Convention over configuration (also known as coding by convention) is a software design paradigm
Design paradigm
The term Design paradigm derives from the rather ambiguous idea of paradigm originating in Sociology of Science, which carries at least two main meanings:...

 which seeks to decrease the number of decisions that developers
Software developer
A software developer is a person concerned with facets of the software development process. Their work includes researching, designing, developing, and testing software. A software developer may take part in design, computer programming, or software project management...

 need to make, gaining simplicity, but not necessarily losing flexibility.

The phrase essentially means a developer only needs to specify unconventional aspects of the application. For example, if there's a class Sale in the model, the corresponding table in the database is called “sales” by default. It is only if one deviates from this convention, such as calling the table “products_sold”, that one needs to write code regarding these names.

When the convention implemented by the tool you are using matches your desired behavior, you enjoy the benefits without having to write configuration files. When your desired behavior deviates from the implemented convention, then you configure your desired behavior.

Motivation

Some frameworks need multiple configuration files, each with many settings. These provide information specific to each project, ranging from URLs to mappings between classes and database tables. A large number of configuration files with lots of parameters is often an indicator of an unnecessarily complex application design.

For example, early versions of the well-known Java persistence mapper Hibernate
Hibernate (Java)
Hibernate is an object-relational mapping library for the Java language, providing a framework for mapping an object-oriented domain model to a traditional relational database...

 mapped entities and their fields to the database by describing these relationships in XML files. Most of this information could have been revealed by conventionally mapping class names to the identically named database
Database
A database is an organized collection of data for one or more purposes, usually in digital form. The data are typically organized to model relevant aspects of reality , in a way that supports processes requiring this information...

 tables and the fields to its columns, respectively. Later versions did away with the XML
XML
Extensible Markup Language is a set of rules for encoding documents in machine-readable form. It is defined in the XML 1.0 Specification produced by the W3C, and several other related specifications, all gratis open standards....

 configuration file and instead employed these very conventions, deviations from which can be indicated through the use of Java annotation
Annotation
An annotation is a note that is made while reading any form of text. This may be as simple as underlining or highlighting passages.Annotated bibliographies give descriptions about how each source is useful to an author in constructing a paper or argument...

s (see JavaBeans specification, linked below).

Usage

Many modern frameworks use a convention over configuration approach. A few such frameworks include: Spring, Ruby on Rails
Ruby on Rails
Ruby on Rails, often shortened to Rails or RoR, is an open source web application framework for the Ruby programming language.-History:...

, EJB, JSF
JavaServer Faces
JavaServer Faces is a Java-based Web application framework intended to simplify development integration of web-based user interfaces....

, Stripes
Stripes (framework)
-External links:********...

, Kohana PHP
Kohana Framework
Kohana PHP is an HMVC PHP5 framework that provides a rich set of components for quickly building robust and dynamic web applications. It is a relatively lesser known framework when compared to other, such as CakePHP or CodeIgniter, and has a small "strong but elite" community...

, Grails
Grails (Framework)
Grails is an open source web application framework which uses the Groovy programming language . It is intended to be a high-productivity framework by following the "coding by convention" paradigm, providing a stand-alone development environment and hiding much of the configuration detail from the...

, Grok
Grok (web framework)
Grok is an open-source Web framework based on Zope Toolkit technology. The project was started in 2006 by a number of Zope developers. Grok has since then seen regular releases...

, Zend Framework
Zend Framework
Zend Framework is an open source, object-oriented web application framework implemented in PHP 5 and licensed under the New BSD License.-Licensing:...

, Pylons, CakePHP
CakePHP
CakePHP is an open source web application framework for producing web applications. It is written in PHP, modeled after the concepts of Ruby on Rails, and distributed under the MIT License.-History:...

, symfony
Symfony
Symfony is a web application framework written in PHP which follows the model-view-controller paradigm. Released under the MIT license, Symfony is free software...

, Maven
Apache Maven
Maven is a build automation and software comprehension tool. While primarily used for Java programming, it can also be used to build and manage projects written in C#, Ruby, Scala, and other languages. Maven serves a similar purpose to the Apache Ant tool, but it is based on different concepts and...

, ASP.NET MVC, ColdFusion on Wheels
ColdFusion on Wheels
ColdFusion on Wheels is an open source web application framework designed for applications written in ColdFusion Markup Language. Its name is often shortened to CFWheels or Wheels....

, Web2py
Web2py
Web2py is an open source web application framework. Web2py is written in the Python language and is programmable in Python. Since web2py was originally designed as a teaching tool with emphasis on ease of use and deployment, it does not have any project-level configuration files. Web2py was...

 (MVC), Apache Wicket and the OutSystems Agile Platform
OutSystems
OutSystems is a multinational software company which operates in the agile software development market. The company’s mission is to provide technology that speeds up and reduces the costs of the delivery and management of web business applications using agile methodologies.OutSystems' flagship...

.

The concept is older, however, and can be spotted even in the roots of Java
Java (programming language)
Java is a programming language originally developed by James Gosling at Sun Microsystems and released in 1995 as a core component of Sun Microsystems' Java platform. The language derives much of its syntax from C and C++ but has a simpler object model and fewer low-level facilities...

 libraries. For example, the JavaBean specification relies on it heavily. To quote the JavaBeans specification 1.01:
"As a general rule we don't want to invent an enormous java.beans.everything class that people have to inherit from. Instead we'd like the JavaBeans runtimes to provide default behaviour for 'normal' objects, but to allow objects to override a given piece of default behaviour by inheriting from some specific java.beans.something interface."

External links

The source of this article is wikipedia, the free encyclopedia.  The text of this article is licensed under the GFDL.
 
x
OK