The single responsibility principle has a big impact on adaptability of code. Provide an explanation supported with detailed examples
Answer:
The Single Responsibility Principle is the key software engineering principle which determines how we should modularise code in object oriented programming.Single Responsibility Principle (SRP) and its importance cannot be overstated. I would even argue that it is a necessary and sufficient condition for good code. In fact, in any code that is badly written, you can always find a class that has more than one responsibility containing a few thousand lines of code is not something that rare to come by and all of us probably have seen or done it.
example:
public class OrderController
{
...
public ActionResult CreateForm()
{
/*
* View data preparations
*/
return View();
}
[HttpPost]
public ActionResult Create(OrderCreateRequest request)
{
if (!ModelState.IsValid)
{
/*
* View data preparations
*/
return View();
}
using (var context = new DataContext())
{
var order = new Order();
// Create order from request
context.Orders.Add(order);
// Reserve ordered goods
…(Huge logic here)...
context.SaveChanges();
//Send email with order details for customer
}
return RedirectToAction("Index");
}
... (many more methods like Create here)
}
Notice in the snippet of code above how the controller knows too much about “placing an order”, including but not limited to storing the Order object, sendings emails, etc. That is simply too many jobs for a single class. For every little change, the developer needs to change the entire controller’s code. And just in case another Controller also needs to create orders, more often than not, developers will resort to copy-pasting the code. Controllers should only control the overall process, and not actually house every bit of logic of the process.
Let us first extract all business logic from the controller and move it to a OrderService class:
public class OrderService
{
public void Create(OrderCreateRequest request)
{
// all actions for order creating here
}
}
public class OrderController
{
public OrderController()
{
this.service = new OrderService();
}
[HttpPost]
public ActionResult Create(OrderCreateRequest request)
{
if (!ModelState.IsValid)
{
/*
* View data preparations
*/
return View();
}
this.service.Create(request);
return RedirectToAction("Index");
}
With this done, the controller now only does only what it is intended to do: control the process. It knows only about views, OrderService and OrderRequest classes - the least set of information required for it to do its job, which is managing requests and sending responses.
The single responsibility principle has a big impact on adaptability of code. Provide an explanation supported...
Write some java code that has a syntax error. Provide your explanation of the error, the consequence of such error
Write some java code to show that it has a runtime error. Provide your explanation of the error. What is the consequence of such error?
provide explanation how you would complete a milestone with
the given time period
Your group has already selected a business in Assignment #1 and 2 that you want to start and The Pas, Thompson or your community. Explain the following terms considering your selected business using real-life data/information as required 1. Implementation Schedule This section of the feasibility study explains a detailed schedule for implementation of the product or service that you have considered in Assignment #1 and 2. This...
Can someone please provide a detailed explanation of the
solution
DO IT! 3 Inventory Errors Visual Company overstated its 2018 ending inventory by $22,000. Determine the impact this error has on ending inventory, cost of goods sold, and stockholders' equity in 2018 and 2019. Action Plan An ending inventory error in one period will have an equal and opposite effect on cost of goods sold and net income in the next period. ✓ After two years, the errors have offset...
Please provide full detailed explanation. Thank you.
7 The CEO of Newark Inc. has provided you with the following information for its operation for 2013. Dollar figures are in thousands. TVC? Sales Revenue Cost of goods sold Total contribution margin Fixed costs: manufacturing Fixed costs: selling and administrative Variable selling expense $200 40 20 20 076 The tax rate for Newark is 25% if they want to increase the after-tax ncome for 2014 by $12. by how much do they...
Please provide detailed explanation. will rate surely!!
PARTA The ion [Ni(Pyridine), (H,0,12+ has d - d absorption bands at 27000, 16500 and 10150 cm-7. The 10 Dq value of Ni2+ ion is: (A) 10150 cm? (B) 10500 cm- (C) 16500 cm-1 D) 6350 cm- PART B Oxyhemoglobin is diamagnetic due to electron spin coupling between (A) Low spin Fe2+ and oxygen molecule (B) High spin Fe3+ and superoxide radical (C) High spin Fe2+ and oxygen molecule (D) Low spin Fe3+...
NO ONE HAS PROVIDED THE CORRECT CODE TO PROVIDE THE GIVEN OUTPUT. PLEASE PROVIDE CODE THAT WOULD CAUSE THE HW1.java TO PRINT THE RIGHT DATA.!!! The LinkedList class implements both the List interface and the Stack interface, but several methods (listed below) are missing bodies. Write the code so it works correctly. You should submit one file, LinkedList.java. Do not change the interfaces. Do not change the public method headers. Do not rename the LinkedList class. None of your methods...
Summarize each parts(provide a thoughtful, complete (yet concise) overview, Do not include any direct quotes from your text or any other source) 1. One of the earliest ethics codes was the Nuremberg Code—a set of 10 principles written in 1947 in conjunction with the trials of Nazi physicians accused of shockingly cruel research on concentration camp prisoners during World War II. It provided a standard against which to compare the behavior of the men on trial—many of whom were eventually...
Assembly Code
may I get an explanation for the 3 parts in this question
Given that . Ar is a label at address 510 EAX has the value 139 . EBX has the value 102 Which bytes in memory will be accessed by the instruction movl $Ar + 38, %ecx Write your answer in the form startByteEndByte with no space in between. If memory is NOT accessed write -1 for your answer. For example, if your answer was bytes 527...
Vernon Corporation has three divisions, each operating as a responsibility center. To provide an incentive for divisional executive officers, the company gives divisional management a bonus equal to 17 percent of the excess of actual net income over budgeted net income. The following is Atlantic Division's current year's performance. Sales revenue Cost of goods sold Gross profit Selling & administrative expenses Net income Current Year $4,110,000 2,480,000 1,630,000 760,000 $ 870,000 The president has just received next year's budget proposal...