views:

639

answers:

8

What is separation of concerns? What's a concern?

How might one partition an app into these "different concerns"?

+2  A: 

Wikipedia:

In computer science, separation of concerns (SoC) is the process of breaking 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 and encapsulation, with the help of information hiding.

I post this not to gain rep, but to wonder why you would ask a question that can so easily be answered.

Aaron
to see what kind of answers might get..i didn't expect to get wikipedia pasted as an answer 10 times..lol
therealhoff
+9  A: 

http://en.wikipedia.org/wiki/Separation_of_concerns

In computer science, separation of concerns (SoC) is the process of breaking 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 and encapsulation, with the help of information hiding.

Simucal
A: 

This principle states that a given problem involves different kinds of concerns, which should be identified and separated to cope with complexity, and to achieve the required engineering quality factors such as robustness, adaptability, maintainability, and reusability. Link

Nescio
+1  A: 

Generally speaking, it means that you segregate your software into distinct areas whose functionality does not overlap.

Wikipedia has a good explanation:

http://en.wikipedia.org/wiki/Separation_of_concerns

Ian P
+7  A: 

Concerns are the different aspects of software functionality. For instance, the "business logic" of software is a concern, and the interface through which a person uses this logic is another.

The separation of concerns is keeping the code for each of these concerns separate. Changing the interface should not require changing the business logic code, and vice versa.

Model-View-Controller (MVC) design pattern is an excellent example of separating these concerns for better software maintainability.

For more information:

Lucas Oman
A: 

Not really an answer to your question, but if you're interested in this, there's a related design pattern called Dependency Inversion.

Let's say you have a class with a method that needs to be influenced from outside the class, or you need multiple implementations of it, or the fact that it's a method of that class makes unit testing difficult. You can put that method in a completely separate class, and pass the instance of the first class in as a parameter.

This is especially useful when using mock interfaces. You can test the method by passing in mocks for the other class with hard-coded values and expected results.

dj_segfault
+3  A: 

You know about HTML and CSS? That's separation of concerns right there.

The HTML file (possibly XML) defines the document structure. The CSS file defines how the document is presented on your screen.

mbac32768
Good example! It can be easily adapted to different programs, by separating controller logic from presentation layer (ok, a trivial example).
phjr
+1  A: 

It is described at the wikipedia: http://en.wikipedia.org/wiki/Separation_of_concerns

It is the value stated in the Single Responsibility Principle, that a function/class/method should do only one thing. That it should do it all, do it well, and do it only. You can read about it at: http://www.objectmentor.com/resources/articles/srp.pdf

Basically, it means you shouldn't munge your ideas together into a lumpy paste, but you should separate your ideas cleanly in code. If you don't, it is hard to change, test, or debug the code. If you do separate them, then you have some freedom to change. For instance, if you munge your html generator with your query, you will find it hard to change the formatting, and you will find it hard to switch to a different query. If you separate them, then both of those things become easy. Or easier, at least.

Tim Ottinger