辅导案例-3815ICT
2805ICT: System and Software Design3815ICT Software Engineering7805ICT Principles of Software EngineeringWorkshop 07Vladimir Estivill-CastroLarry WenAugust 31, 2019Objectives1. Review software patterns in the context of web architecture.2. Identify fundamental challenges of web architectures.3. Review a MVC-framework for Web-architectures.4. Discuss the issues regarding web architectures.Software PatternsActivity 1Study the entry in Wikipedia for the “Command pattern”(en.wikipedia.org/wiki/Command_pattern).Review the following piece of code. Explain why this represents an anti-pattern:if (op==1){ User u = new User( request.getAttribute("user"), request.getAttribute("pass"));}else if (op==2){ ... }...What are the disadvantages of the template suggested by the anti-pattern above?1Activity 2Examine the code below that defines an abstract class. What part of the Command patterndoes this achieve? What does the constructor achieve?//Action.javapublic abstract class Action{protected Model model;public Action(Model model){this.model = model;}public abstract String getName();public abstract Object perform(HttpServletRequest req);}Activity 3Examine the code below that defines a concrete class. What part of the Command patterndoes this achieve? What does the constructor achieve? Explain the method getName().// CreateUserAction.java:public class CreateUserAction extends Action{public CreateUserAction(Model model){super(model);}public String getName(){return "createUser";}public Object perform(HttpServletRequest req){return model.createUser(req.getAttribute("user"),req.getAttribute("pass"));}}Activity 4Examine the code below that defines a concrete class. What part of the Command patterndoes this achieve? Is this linked to some part of MVC?public class ControllerServlet extends HttpServlet {private HashMap actions;public void init() throws ServletException {actions = new HashMap();CreateUserAction que = new CreateUserAction(model);actions.put(que.getName(), que);//... create and add more actions}public void doPost(HttpServletRequest req, HttpServletResponse resp)throws IOException, ServletException {// First identify operation "op" from URL.// method getOperation() is defined elsewhere.String op = getOperation(req.getRequestURL());// Then find and execute corresponding ActionAction action = (Action)actions.get(op);Object result = null;try {result = action.perform(req);} catch (NullPointerException npx) { ... }//determine next view result to determine next view}...}2Web ArchitectureActivity 5Study the short entry in Wikipedia for the “Stateless protocol”(en.wikipedia.org/wiki/Stateless_protocol).Research the concept of session and discuss what are the implications that the HTTPprotocol of the Web is stateless with respect to sessions?Activity 6Frameworks for Web architectures are very varied. Even for Java Server pages there areseveral variants. Browse over the chapter “The Spring Web MVC Framework” (availableat Learning@GU).Identify 4 advantages that this chapter attributes to the Spring Web MVC Framework.Activity 7Attempt to complete the tutorial named “Introduction to Spring Web MVC”(netbeans.org/kb/docs/web/quickstart-webapps-spring.html)This tutorial can be followed with almost no background on Java Server Pages (JSP) orjava beans. Although learning about such technologies might be useful. The point ofcompeting such exercise is for you to experience a Web architecture based around ModelView Controller (MVC). In particular, several of the components are configured by settingproperties in XML-files, for example.I recommend you follow this tutorial using NetBeans. You will probably find that youshould install some plug-ins so you can complete the tutorial. If you are trying to findthe category "java Web" to create a project of type "Web Application" you probably aremissing the “java EE Base”, and if you find that after creating some project you aremissing some libraries (a message about resources missing), you probably need the "EJBand EAR" plug-in.Similarly, as you develop the project, you will need a WEB server that support Java beans.Chose the GlassFish server, and if it is not installed, NetBeans will fetch it and install itfor you.The entire project will be made available for you in Learning@GU, but it is importantyou attempt to follow the tutorial yourself. Also, you should introduce debugging printstatements so you can follow some of what is going on. The challenge is, how would yourepresent the behavior with an UML sequence diagram?Additional exercises for 3815ICT and 7805ICTThese activities do not earn specific marks, thy enable the marking; that is, if they are not completedthe assessment item is awarded zero regardless of the performance in the previous activities.Activity 8 Write 15 lines of a reflective report on the previous activities. Analyse and evaluate thematch of the activities to the learning objectives proposed in this workshop/laboratory.3Additional exercises for 7805ICTActivity 9Design an open ended question (that means there may be several correct answers) thatevaluates the learning objectives of this workshop and could be suitable for1. a midterm, or2. a final exam, or3. a job interview for software engineering.4