Refactor procedural method using OO principles

I have a method where I want to factor out some code into its own method This is what I have: public class TD0301AssignmentForm extends Form { public TD0301AssignmentForm(TD0301AssignmentDAO dao, STKUser authenticatedUser) { this.dao = dao; this.authenticatedUser = authenticatedUser; } public Object insert(HttpServletRequest request) { TD0301Assignment tdas = new TD0301Assignment(); TD0301Assignment tdas_orig = null; Date dateNow = new Date(); try { // Get the inuput from HTML form tdas.setCalc_num(FormUtil.getFieldValue(request, FIELD_CALC_NUM)); processDate(request, tdas); tdas.setCalc_dept(FormUtil.getFieldValue(request, FIELD_CALC_DEPT)); tdas.setYear_oi(Integer.toString(DateUtil.getIntYear(dateNow))); processCalcSafetyRequirements(request, tdas); ...etc... if (isSucces()) { // Instantiate a base work flow instance! WorkflowInstance wfi = new WorkflowInstance(); WorkflowInstanceDAO wfiDAO = new WorkflowInstanceDAO(); wfi.setWorkflow_class_id(tdas.getCalc_level()); wfi.setStarted_by(authenticatedUser.getBadge()); wfi.setStatus("0"); wfi.setLast_date(dateNow); // Insert the WorkFlowInstance into the database, db sets returned sequence number into the wfi object. wfiDAO.insert(wfi, authenticatedUser); // Insert the TD0301Assignment into the db tdas.setWorkflow_instance_id(wfi.getWorkflow_instance_id()); } I'd like to remove the `WorkflowInstance` code out into its own method (still in this Class) like this: if (isSucces()) { insertWorkFlowInstance(request, tdas); tdas.setWorkflow_instance_id(wfi.getWorkflow_instance_id()); but `wfi` is now marked by Eclipse as not available. Should I do something like this to fix the error so that I can still get the `wfi.getWorkflow_instance_id()` in the isSuccess block above? I know it removes the error, but I am trying to apply best practices. public class TD0301AssignmentForm extends Form { private WorkflowInstance wfi = new WorkflowInstance(); private WorkflowInstanceDAO wfiDAO = new WorkflowInstanceDAO();

以上就是Refactor procedural method using OO principles的详细内容,更多请关注web前端其它相关文章!

赞(0) 打赏
未经允许不得转载:web前端首页 » JavaScript 答疑

评论 抢沙发

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址

前端开发相关广告投放 更专业 更精准