Separation of concerns
Encyclopedia
In computer science
, separation of concerns (SoC) is the process of separating a computer program
into distinct features that overlap in functionality as little as possible. A concern
is any piece of interest or focus in a program. Typically, concerns are synonymous with features or behaviors. Progress towards SoC is traditionally achieved through modularity
of programming and encapsulation (or "transparency" of operation), with the help of information hiding
. Layered designs in information systems are also often based on separation of concerns (e.g., presentation layer, business logic layer, data access layer, database layer).
languages such as Delphi, C++
, Java
, and C# can separate concerns into objects
, and a design pattern
like MVC
can separate content from presentation
and data-processing (model) from content.
Service-oriented design
can separate concerns into services. Procedural programming
languages such as C
and Pascal
can separate concerns into procedures. Aspect-oriented programming
languages can separate concerns into aspects
and objects
.
Separation of concerns is an important design principle in many other areas as well, such as urban planning
, architecture
and information design
. The goal is to design systems so that functions can be optimized independently of other functions, so that failure of one function does not cause other functions to fail, and in general to make it easier to understand, design and manage complex interdependent systems. Common examples include using corridors to connect rooms rather than having rooms open directly into each other, and keeping the stove on one circuit and the lights on another.
Fifteen years later, it was evident the term Separation of Concerns was becoming an accepted idea. In 1989, Chris Reade wrote a book titled "Elements of Functional Programming"
that describes separation of concerns:
Reade continues to say,
, great efforts have been made to separate concerns into well-defined layers. This allows protocol designers to focus on the concerns in one layer, and ignore the other layers. The Application Layer protocol SMTP, for example, is concerned about all the details of conducting an email session over a reliable transport service (usually TCP), but not the least concerned about how the transport service makes that service reliable. Similarly, TCP is not concerned about the routing of data packets, which is handled at the Internet Layer
.
(HTML) and Cascading Style Sheets
(CSS) are complementary languages used in the development of webpages and websites. HTML is mainly used for organization of webpage content and CSS is used for definition of content presentation style. Historically, this was not the case though. Prior to the introduction of CSS, HTML performed both duties.
allows separate concerns to be addressed as separate software constructs, each on an equal footing with the others. Each concern provides its own class-structure into which the objects in common are organized, and contributes state and methods to the composite result where they cut across one another. Correspondence rules describe how the classes and methods in the various concerns are related to each other at points where they interact, allowing composite behavior for a method to be derived from several concerns. Multi-dimensional Separation of Concerns allows the analysis and composition of concerns to be manipulated as a multi-dimensional "matrix" in which each concern provides a dimension in which different points of choice are enumerated, with the cells of the matrix occupied by the appropriate software artifacts.
allows cross-cutting concern
s to be addressed as secondary concerns. For example, most programs require some form of security
and logging. Security and logging are often secondary concerns, whereas the primary concern is often on accomplishing business goals.
is an approach to automating the process of compiling source code into binary code. The primary goals in build automation are reducing the risk of human error and saving time.
implemented in different parts.
Bear_Hunting.cs:
Bear_Eating.cs:
Bear_Hunger.cs:
For example, if we want to compile a version without support for hunger management (it could be a feature that costs extra for your customers), we simply remove the partial declaration in Bear_Hunger.cs.
Now if a program also supported hunger management in other classes all those partial class definitions could go in a separate 'Hunger' directory. This is what is usually called multidimensional separation of concerns, and it helps programmers update the code and add new features, even the first time anyone started working with this code.
bear_eating.rb
bear_hunger.rb
Computer science
Computer science or computing science is the study of the theoretical foundations of information and computation and of practical techniques for their implementation and application in computer systems...
, separation of concerns (SoC) is the process of separating a computer program
Computer program
A computer program is a sequence of instructions written to perform a specified task with a computer. A computer requires programs to function, typically executing the program's instructions in a central processor. The program has an executable form that the computer can use directly to execute...
into distinct features that overlap in functionality as little as possible. A concern
Concern (computer science)
In computer science, a concern is a particular set of behaviors needed by a computer program, the conceptual sections. A concern can be as general as database interaction or as specific as performing a calculation, depending on the level of conversation between developers and the program being...
is any piece of interest or focus in a program. Typically, concerns are synonymous with features or behaviors. Progress towards SoC is traditionally achieved through modularity
Modularity (programming)
Modular programming is a software design technique that increases the extent to which software is composed of separate, interchangeable components called modules by breaking down program functions into modules, each of which accomplishes one function and contains everything necessary to accomplish...
of programming and encapsulation (or "transparency" of operation), with the help of information hiding
Information hiding
In computer science, information hiding is the principle of segregation of the design decisions in a computer program that are most likely to change, thus protecting other parts of the program from extensive modification if the design decision is changed...
. Layered designs in information systems are also often based on separation of concerns (e.g., presentation layer, business logic layer, data access layer, database layer).
Implementation
All programming paradigms aid developers in the process of improving SoC. For example, object-oriented programmingObject-oriented programming
Object-oriented programming is a programming paradigm using "objects" – data structures consisting of data fields and methods together with their interactions – to design applications and computer programs. Programming techniques may include features such as data abstraction,...
languages such as Delphi, C++
C++
C++ is a statically typed, free-form, multi-paradigm, compiled, general-purpose programming language. It is regarded as an intermediate-level language, as it comprises a combination of both high-level and low-level language features. It was developed by Bjarne Stroustrup starting in 1979 at Bell...
, 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...
, and C# can separate concerns into objects
Object (computer science)
In computer science, an object is any entity that can be manipulated by the commands of a programming language, such as a value, variable, function, or data structure...
, and a design pattern
Design pattern (computer science)
In software engineering, a design pattern is a general reusable solution to a commonly occurring problem within a given context in software design. A design pattern is not a finished design that can be transformed directly into code. It is a description or template for how to solve a problem that...
like MVC
Model-view-controller
Model–view–controller is a software architecture, currently considered an architectural pattern used in software engineering. The pattern isolates "domain logic" from the user interface , permitting independent development, testing and maintenance of each .Model View Controller...
can separate content from presentation
Separation of presentation and content
Separation of presentation and content is a common idiom, a design philosophy, and a methodology applied in the context of various publishing technology disciplines, including information retrieval, template processing, web design, web development, word processing, desktop publishing,...
and data-processing (model) from content.
Service-oriented design
Service-orientation
Service-orientation is a design paradigm to build computer software in the form of services. Like other design paradigms , service-orientation provides a governing approach to automate business logic as distributed systems...
can separate concerns into services. Procedural programming
Procedural programming
Procedural programming can sometimes be used as a synonym for imperative programming , but can also refer to a programming paradigm, derived from structured programming, based upon the concept of the procedure call...
languages such as C
C (programming language)
C is a general-purpose computer programming language developed between 1969 and 1973 by Dennis Ritchie at the Bell Telephone Laboratories for use with the Unix operating system....
and Pascal
Pascal (programming language)
Pascal is an influential imperative and procedural programming language, designed in 1968/9 and published in 1970 by Niklaus Wirth as a small and efficient language intended to encourage good programming practices using structured programming and data structuring.A derivative known as Object Pascal...
can separate concerns into procedures. Aspect-oriented programming
Aspect-oriented programming
In computing, aspect-oriented programming is a programming paradigm which aims to increase modularity by allowing the separation of cross-cutting concerns...
languages can separate concerns into aspects
Aspect (computer science)
In computer science, an aspect of a program is a feature linked to many other parts of the program, but which is not related to the program's primary function. An aspect crosscuts the program's core concerns, therefore violating its separation of concerns that tries to encapsulate unrelated functions...
and objects
Object (computer science)
In computer science, an object is any entity that can be manipulated by the commands of a programming language, such as a value, variable, function, or data structure...
.
Separation of concerns is an important design principle in many other areas as well, such as urban planning
Urban planning
Urban planning incorporates areas such as economics, design, ecology, sociology, geography, law, political science, and statistics to guide and ensure the orderly development of settlements and communities....
, architecture
Architecture
Architecture is both the process and product of planning, designing and construction. Architectural works, in the material form of buildings, are often perceived as cultural and political symbols and as works of art...
and information design
Information design
Information design is the skill and practice of preparing information so people can use it with efficiency and effectiveness. Where the data is complex or unstructured, a visual representation can express its meaning more clearly to the viewer....
. The goal is to design systems so that functions can be optimized independently of other functions, so that failure of one function does not cause other functions to fail, and in general to make it easier to understand, design and manage complex interdependent systems. Common examples include using corridors to connect rooms rather than having rooms open directly into each other, and keeping the stove on one circuit and the lights on another.
Origin
The term separation of concerns was probably coined by Edsger W. Dijkstra in his 1974 paper "On the role of scientific thought".
Let me try to explain to you, what to my taste is characteristic for all intelligent thinking. It is, that one is willing to study in depth an aspect of one's subject matter in isolation for the sake of its own consistency, all the time knowing that one is occupying oneself only with one of the aspects. We know that a program must be correct and we can study it from that viewpoint only; we also know that it should be efficient and we can study its efficiency on another day, so to speak. In another mood we may ask ourselves whether, and if so: why, the program is desirable. But nothing is gained --on the contrary!-- by tackling these various aspects simultaneously. It is what I sometimes have called "the separation of concerns", which, even if not perfectly possible, is yet the only available technique for effective ordering of one's thoughts, that I know of. This is what I mean by "focusing one's attention upon some aspect": it does not mean ignoring the other aspects, it is just doing justice to the fact that from this aspect's point of view, the other is irrelevant. It is being one- and multiple-track minded simultaneously.
Fifteen years later, it was evident the term Separation of Concerns was becoming an accepted idea. In 1989, Chris Reade wrote a book titled "Elements of Functional Programming"
that describes separation of concerns:
The programmer is having to do several things at the same time, namely,
1. describe what is to be computed;
2. organise the computation sequencing into small steps;
3. organise memory management during the computation.
Reade continues to say,
Ideally, the programmer should be able to concentrate on the first of the three tasks (describing what is to be computed) without being distracted by the other two, more administrative, tasks. Clearly, administration is important but by separating it from the main task we are likely to get more reliable results and we can ease the programming problem by automating much of the administration.
The separation of concerns has other advantages as well. For example, program proving becomes much more feasible when details of sequencing and memory management are absent from the program. Furthermore, descriptions of what is to be computed should be free of such detailed step-by-step descriptions of how to do it if they are to be evaluated with different machine architectures. Sequences of small changes to a data object held in a store may be an inappropriate description of how to compute something when a highly parallel machine is being used with thousands of processors distributed throughout the machine and local rather than global storage facilities.
Automating the administrative aspects means that the language implementor has to deal with them, but he/she has far more opportunity to make use of very different computation mechanisms with different machine architectures.
Internet Protocol Stack
Separation of concerns is crucial to the design of the Internet. In the Internet Protocol SuiteInternet protocol suite
The Internet protocol suite is the set of communications protocols used for the Internet and other similar networks. It is commonly known as TCP/IP from its most important protocols: Transmission Control Protocol and Internet Protocol , which were the first networking protocols defined in this...
, great efforts have been made to separate concerns into well-defined layers. This allows protocol designers to focus on the concerns in one layer, and ignore the other layers. The Application Layer protocol SMTP, for example, is concerned about all the details of conducting an email session over a reliable transport service (usually TCP), but not the least concerned about how the transport service makes that service reliable. Similarly, TCP is not concerned about the routing of data packets, which is handled at the Internet Layer
Internet layer
The internet layer or IP layer is a group of internetworking methods in the Internet protocol suite, commonly also called TCP/IP, which is the foundation of the Internet...
.
HTML and CSS
HyperText Markup LanguageHTML
HyperText Markup Language is the predominant markup language for web pages. HTML elements are the basic building-blocks of webpages....
(HTML) and Cascading Style Sheets
Cascading Style Sheets
Cascading Style Sheets is a style sheet language used to describe the presentation semantics of a document written in a markup language...
(CSS) are complementary languages used in the development of webpages and websites. HTML is mainly used for organization of webpage content and CSS is used for definition of content presentation style. Historically, this was not the case though. Prior to the introduction of CSS, HTML performed both duties.
Subject-oriented programming
Subject-oriented programmingSubject-oriented programming
In computing, Subject-Oriented Programming is an object-oriented software paradigm in which the state and behavior of objects are not seen as intrinsic to the objects themselves, but are provided by various subjective perceptions of the objects...
allows separate concerns to be addressed as separate software constructs, each on an equal footing with the others. Each concern provides its own class-structure into which the objects in common are organized, and contributes state and methods to the composite result where they cut across one another. Correspondence rules describe how the classes and methods in the various concerns are related to each other at points where they interact, allowing composite behavior for a method to be derived from several concerns. Multi-dimensional Separation of Concerns allows the analysis and composition of concerns to be manipulated as a multi-dimensional "matrix" in which each concern provides a dimension in which different points of choice are enumerated, with the cells of the matrix occupied by the appropriate software artifacts.
Aspect-oriented programming
Aspect-oriented programmingAspect-oriented programming
In computing, aspect-oriented programming is a programming paradigm which aims to increase modularity by allowing the separation of cross-cutting concerns...
allows cross-cutting concern
Cross-cutting concern
In computer science, cross-cutting concerns are aspects of a program which affect other concerns.These concerns often cannot be cleanly decomposed from the rest of the system in both the design and implementation, and can result in either scattering , tangling , or both.For instance, if writing an...
s to be addressed as secondary concerns. For example, most programs require some form of security
Computer security
Computer security is a branch of computer technology known as information security as applied to computers and networks. The objective of computer security includes protection of information and property from theft, corruption, or natural disaster, while allowing the information and property to...
and logging. Security and logging are often secondary concerns, whereas the primary concern is often on accomplishing business goals.
Software build automation
Most project organization tasks are seen as secondary tasks. For example, build automationBuild Automation
Build automation is the act of scripting or automating a wide variety of tasks that software developers do in their day-to-day activities including things like:* compiling computer source code into binary code* packaging binary code* running tests...
is an approach to automating the process of compiling source code into binary code. The primary goals in build automation are reducing the risk of human error and saving time.
SoC via partial classes
Separation of concerns can be implemented and enforced via partial classes.SoC via partial classes in C#
The following Bear class, written in C#, has different aspectsAspect (computer science)
In computer science, an aspect of a program is a feature linked to many other parts of the program, but which is not related to the program's primary function. An aspect crosscuts the program's core concerns, therefore violating its separation of concerns that tries to encapsulate unrelated functions...
implemented in different parts.
Bear_Hunting.cs:
Bear_Eating.cs:
Bear_Hunger.cs:
For example, if we want to compile a version without support for hunger management (it could be a feature that costs extra for your customers), we simply remove the partial declaration in Bear_Hunger.cs.
Now if a program also supported hunger management in other classes all those partial class definitions could go in a separate 'Hunger' directory. This is what is usually called multidimensional separation of concerns, and it helps programmers update the code and add new features, even the first time anyone started working with this code.
SoC via partial classes in Ruby
bear_hunting.rbbear_eating.rb
bear_hunger.rb
See also
- Abstraction principle (programming)Abstraction principle (programming)In software engineering and programming language theory, the abstraction principle is a basic dictum that aims to reduce duplication of information in a program whenever practical by making use of abstractions provided by the programming language or software libraries...
- Aspect-oriented software developmentAspect-oriented software developmentIn computing, Aspect-oriented software development is an emerging software development technology that seeks new modularizations of software systems in order to isolate secondary or supporting functions from the main program's business logic...
- Concern (computer science)Concern (computer science)In computer science, a concern is a particular set of behaviors needed by a computer program, the conceptual sections. A concern can be as general as database interaction or as specific as performing a calculation, depending on the level of conversation between developers and the program being...
- Core concernCore concernIn computer science, a core concern is one of the main concerns a program is written for. The main coding of the application is to satisfy the core concerns, such as doing the tasks as visualized...
- Cross-cutting concernCross-cutting concernIn computer science, cross-cutting concerns are aspects of a program which affect other concerns.These concerns often cannot be cleanly decomposed from the rest of the system in both the design and implementation, and can result in either scattering , tangling , or both.For instance, if writing an...
- HolismHolismHolism is the idea that all the properties of a given system cannot be determined or explained by its component parts alone...
- Modular designModular designModular design, or "modularity in design" is an approach that subdivides a system into smaller parts that can be independently created and then used in different systems to drive multiple functionalities...
- Modular programmingModular programmingModular programming is a software design technique that increases the extent to which software is composed of separate, interchangeable components called modules by breaking down program functions into modules, each of which accomplishes one function and contains everything necessary to accomplish...
- Separation of presentation and contentSeparation of presentation and contentSeparation of presentation and content is a common idiom, a design philosophy, and a methodology applied in the context of various publishing technology disciplines, including information retrieval, template processing, web design, web development, word processing, desktop publishing,...
- Coupling (computer science)Coupling (computer science)In computer science, coupling or dependency is the degree to which each program module relies on each one of the other modules.Coupling is usually contrasted with cohesion. Low coupling often correlates with high cohesion, and vice versa...