1. Does the following code follow the Single Responsibility Principle?
function createBlogPost(author, date, tags, content) {
generateHeader(author,date)
insertContent(content)
generateFooter(tags)
}
2. You are tasked with adding a new type of item to an online retail store. The item is unique because it comes in multiple colors and also can be purchased with different currencies depending on the shipping address.
Based on the Single Responsibility Principle, how many responsibilities exist in this task?
3. What does Single Responsibility mean in the Single Responsibility Principle?
4. Does the following code adhere to the Single Responsibility principle?
function detectLanguageHandler(req,resp) {
var language = '';
if (req.params.greeting === "hello") {
language = "English;
} else if (req.params.greeting === "bonjour" ) {
language = "French"
} else {
return resp.reply("Invalid greeting input").statusCod(422);
return resp.reply("Detected langauge is " + language).statusCode(200).
}
5. Why is high cohesion not a violation of the Single Responsibility Principle?