CSC/ECE 517 Fall 2007/wiki3 3 33

From Expertiza_Wiki
Jump to navigation Jump to search

Topic - Separation of Responsibility

Take the principle of Separation of Responsibility and catalog the information on it available on the Web. Find good descriptions and good, concise, understandable examples. Tell which you consider the best to present to a class.'

What is Separation of responsibility

Separation of responsibility (abbreviated as SoR) is also known as seperation of concern (SoC. SoR and SoC will be used interchangably from this point on). In the field of software engineering, this concept probably finds its root in one paper from Dijsktra in the year 1974. Since then SoR became a well accepted concept that helps programmers in designing, implementing and many other aspects of software development.

The essence of the SoR concept is that one foucs on doing one thing and do it well, with out being entangled or distracted by other entity. To elaborate, it is well known that developing a fully functional software in time and meet the needs of clients is challenging due to the intricate nature of the process. Often, software developing requires a group of team developers to cooperate on a project. By effectively seperate out non or minimally overlapped concerns (or tasks, even domains), developers are able to concentrate on just one part of the system, instead of having to worry about all other miniture details. In this way, the integrated system achieve the modulizing effect and is therefore more maintainable. In addition to the benifit of increased maintainability, SoR promotes program extensibility and flexibility. In field of software engineering, the needs of client are characterized by constant changing and modification. By separating an entire system into smaller, "independent" pieces, developers can add, update, delete these parts of the system without dramaticly affect the other parts. This makes modifying the program and adding more functionalities to it far more effecient and easier. Without having SoR, even one small change can trigger a cascading effect that spread to the entire system. Trying to figure out what is going wrong, in this case, will be a nightmare.

Some related concepts

Object Oriented Programming
OO programming paradigm abstracts entities into class/object (an instance of a class) and their behaviors into methods. The target application is built based on these objects and their interactions. OO is a very good example to illustrate the concept of SoR. In OO paradigm, each class with its member variables and methods define an entity. Methods of this class can only be performed on objects belong to this class (with some exceptions like inheritance). Therefore, each class has a particular focus and defines a soft boundaries that separates its own states/behaviors from other classes.
Encapsulation
This refers to hiding implementation and other details of one class from others, exposing only interfaces to be invoked. The purpose of encapsulation is also related to SoR in that by concealing the internal operations of a class, clients who interact with it does not need to concern how the class is implemented, but instead just using it as a black box.
Information Hidding
to be finished
Abstraction
to be finished
Cohesion
to be finished
Coupling
to be finished

SoR categories by scope

class level SoR

project/architecture level SoR

One of the most widely used web and GUI application design pattern - Model-View-Controller (MVC) - stands out as an zealous advocate for the "Separation of Responsibility" philosophy. We think it will be an excellent example to demonstrate the SoR concept in project/architecture level.

picture source: http://www.codeproject.com/useritems/PraticalMvc.asp

As above diagram illurstrated, MVC pattern separates the appliaction into three areas of responsibility to reduce the coupling between modules.

Model
This part is responsible for maintaining the state of the application. Most of the time, this part is related to the data of the system. Through some object relational mapping (ORM), model is used to create/read/update/delete (CRUD) data. What model needs to care is to realize these functionalities correctly and efficiently; it does not need to concern about who will use them, when and how they will be used. (in rare situations, code in model can be involving in other domain)
View
View's responsibility is rendered data, usually from data model, in the correct format and display it to client. This is its sole job. Code in view component does not care about how the backend data is stored, or what the business logic is, no matter how complex it may be.
Controller
Controller's job is receive user's input, performs defined computation, interacts with models, and invoke the appropriate view template to render the result to client.

As we can see, in MVC, code specialized in one category can always be easily found in a well-known location. Each category has its own focus and rarely overlap with others. By doing this, man power can be properly used: web graphic designer who knows HTML/CSS but not much about Java or C# may just focus on view category in MVC, and not worrying about the logic behind the application; programmers may focus on the logic and the correctness of the result, not have to concern about how it will be rendered to users. Database designers may focus on designing a efficient schema to be represented by data models, not anything more nor anything less. When later the application needs to be extended or changed, project manager can easily know who to talk to.


Ruby on Rails is a web application development framework which is based on MVC design pattern.

Aspect-oriented programming

References

http://www.exciton.cs.rice.edu/JavaResources/DesignPatterns/MVC.htm

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

http://www.rubyonrails.org/docs

External Links