Download presentation
Presentation is loading. Please wait.
Published byAlaina Austin Modified over 8 years ago
1
Domain Driven Web Development With WebJinn Sergei Kojarski College of Computer & Information Science Northeastern University joint work with David H. Lorenz http://webjinn.org
2
Outline Background Problem Solution Conclusion Future work & Projects
3
Beginning: Static Pages In the beginning (1991), web was static. People could only browse html pages and no other interaction was allowed….. Resource ClientHTTPWeb-Server Browser Client-server interaction was specified by the HTTP 0.9 protocol, in terms of a simple request/response model…BACKGROUND
4
What about interaction? Web App Web App ClientHTTPWeb Server Browser 1. HTTP was extended to allow user data in the request string 2. Web Server redirects requests to a server-side application 3. Application reads user data, performs server-side actions and dynamically generates HTTP responseBACKGROUND
5
Web Application : closer look An HTTP gateway to a server–side resource Converts between HTTP and Resource terms Normally, doesn’t have complex logicBACKGROUND Web App Web App HTTP Server Resource
6
Web Development Two developer teams: Functionality (e.g., Java, C, Perl) Presentation (e.g., XML, HTML)BACKGROUND
7
Technology #1: CGI scripts public void service(HttpServletRequest request, HttpServletResponse response) { String message=request.getParameter(“message”); response.setContentType("text/html"); PrintStream rs = new PrintStream(response.getOutputStream()); rs.print(“ ”); if (message != null) rs.print(“ ” + message + “ ”) ; else rs.print(“ No message! ”); rs.print(“ ”); } Presentation (HTML) code is embedded into functionality codeBACKGROUND
8
Technology #2: Dynamic Pages No message! Cleaner look More friendly to web designers Easier to change Presentation and functionality are still tangled!BACKGROUND
9
Theory and Practice Well-understood Simple functionality Interactions patterns Difficult to create Complicated implementations No reusable components ConceptState of the artBACKGROUND
10
Background Problem Solution Conclusion Future work & Projects Outline
11
Schema HTTP Resource Schema Functionality server-side operations Presentation HTML response Control high-level control-flow Functionality Presentation Control <%try{ Class.forName("org.gjt.mm.mysql.Driver").newInstance(); java.sql.Connection conn; conn = DriverManager.getConnection( "jdbc:mysql://localhost/database?user=login&password=pass"); try { Statement st = conn.createStatement(); ResultSet rs = st.executeQuery("select name,email,message from guestbook");%> Visitor: '> Guest book is empty. <%} } finally {conn.close();} } catch (Exception e) {%> Server error: The Problem: Tangling and Scattering page code example: nameemailmessage Visitor: PROBLEM PROBLEM
12
Server error: Server error: Separation of concerns <%try{ Class.forName("org.gjt.mm.mysql.Driver").newInstance(); java.sql.Connection conn; conn = DriverManager.getConnection( "jdbc:mysql://localhost/database?user=login&password=pass"); try { PreparedStatement pst = conn.prepareStatement( (“insert into guestbook (name,email,message) values (?,?,?)”); pst.setString(1,request.getParameter(“name”); pst.setString(2,request.getParameter(“email”); pst.setString(3,request.getParameter(“message”); pst.execute(); %> Message was successfully added } finally {conn.close();} } catch (Exception e) {%> <%try{ Class.forName("org.gjt.mm.mysql.Driver").newInstance(); java.sql.Connection conn; conn = DriverManager.getConnection( "jdbc:mysql://localhost/database?user=login&password=pass"); try { Statement st = conn.createStatement(); ResultSet rs = st.executeQuery("select name,email,message from guestbook");%> Visitor: '> Guest book is empty. <%} } finally {conn.close();} } catch (Exception e) {%> New Message Your Name E-mail Message select.jspdoInsert.jsp insertForm.jsp nameemailmessage nameemailmessage pst.setString(1,request.getParameter(“name”); Your Name pst.setString(1,request.getParameter(“email”); pst.setString(1,request.getParameter(“message”); E-mail Message ?,?,? Visitor: Main contribution: schema concern modularization PROBLEM PROBLEM
13
Example:Guestbook PROBLEM PROBLEM
14
Example: Guestbook Typical client-server interaction Typical components (select, insert) Typical problems intra-crosscutting inter-crosscutting PROBLEM PROBLEM
15
Guestbook Architecture Browser guestbook database table SQL queries select.jsp doInsert.jsp insertForm.jsp HTTP PROBLEM PROBLEM Retrieves messages A form for adding a message Posts a new message
16
Select records from guestbook table Print “Content” Load driver and connect to database If table is not empty then Else Print “No records” Close database connection Catch exception Print “Service not available” select.jsp <%try{ Class.forName("org.gjt.mm.mysql.Driver").newInstance(); java.sql.Connection conn; conn = DriverManager.getConnection( "jdbc:mysql://localhost/database?user=login&password=pass"); try { Statement st = conn.createStatement(); ResultSet rs = st.executeQuery("select name,email,message from guestbook");%> Visitor: '> Guest book is empty. <%} } finally {conn.close();} } catch (Exception e) {%> Server error: page codedescription nameemailmessage Visitor: select name, email, message from … nameemailmessage href=“ > PROBLEM PROBLEM
17
Construct and execute SQL insert statement Print “Fail” Print “Message added” doInsert.jsp <%try{ Class.forName("org.gjt.mm.mysql.Driver").newInstance(); java.sql.Connection conn; conn = DriverManager.getConnection( "jdbc:mysql://localhost/database?user=login&password=pass"); try { PreparedStatement pst = conn.prepareStatement( (“insert into guestbook (name, email, message) values (?,?,?)”); pst.setString(1,request.getParameter(“name”); pst.setString(2,request.getParameter(“email”); pst.setString(3,request.getParameter(“message”); pst.execute(); %> Message was successfully added } finally {conn.close();} } catch (Exception e) {%> Server error: Load driver and connect to database Close connection Catch exception page codedescription nameemailmessage pst.setString(1,request.getParameter(“name”); pst.setString(1,request.getParameter(“email”); pst.setString(1,request.getParameter(“message”); ?,?,? PROBLEM PROBLEM
18
insertForm.jsp Return an HTML form that the visitor can fill in order to add a new message into the guestbook. New Message Your Name E-mail Message page codedescription Your Name E-mail Message PROBLEM PROBLEM
19
Intra- versus inter-crosscutting Intra Tangling Dynamic pages Page scoped OOP solution Inter Scattering Dynamic and static Crosscuts pages AOP solution All scheme expressions relate to the same instance insertForm.jsp select.jspdoInsert.jsp Illustration New Message Your Name E-mail Message <%try{ Class.forName("org.gjt.mm.mysql.Driver").newInstance(); java.sql.Connection conn; conn = DriverManager.getConnection( "jdbc:mysql://localhost/database?user=login&password=pass"); try { Statement st = conn.createStatement(); ResultSet rs = st.executeQuery("select name,email,message from guestbook");%> Visitor: '> Guest book is empty. <%} } finally {conn.close();} } catch (Exception e) {%> Server error: <%try{ Class.forName("org.gjt.mm.mysql.Driver").newInstance(); java.sql.Connection conn; conn = DriverManager.getConnection( "jdbc:mysql://localhost/database?user=login&password=pass"); try { PreparedStatement pst = conn.prepareStatement( (“insert into guestbook (name,email,message) values (?,?,?)”); pst.setString(1,request.getParameter(“name”); pst.setString(2,request.getParameter(“email”); pst.setString(3,request.getParameter(“message”); pst.execute(); %> Message was successfully added } finally {conn.close();} } catch (Exception e) {%> Server error: Tangling Scattering Dynamic pages Dynamic and static Page scoped Crosscuts pages OOP solution AOP solution PROBLEM PROBLEM
20
High development cost High maintenance cost Loss of reuse opportunities Increases dependency between developer groups, error-prone, etc. Natural language Correct? Consequence of inter-crosscutting PROBLEM PROBLEM High development cost High maintenance cost Loss of reuse opportunities Changes to the schema trigger complex code updates Cost of schema changes out- weights reuse benefits
21
Outline Background Problem Solution Conclusion Future work
22
<%try{ Class.forName("org.gjt.mm.mysql.Driver").newInstance(); java.sql.Connection conn; conn = DriverManager.getConnection( "jdbc:mysql://localhost/database?user=login&password=pass"); try { PreparedStatement pst = conn.prepareStatement( (“insert into guestbook (name,email,message) values (?,?,?)”); pst.setString(1,request.getParameter(“name”); pst.setString(2,request.getParameter(“email”); pst.setString(3,request.getParameter(“message”); pst.execute(); %> Message was successfully added } finally {conn.close();} } catch (Exception e) {%> Server error: Unweaving inter-crosscutting <%try{ Class.forName("org.gjt.mm.mysql.Driver").newInstance(); java.sql.Connection conn; conn = DriverManager.getConnection( "jdbc:mysql://localhost/database?user=login&password=pass"); try { Statement st = conn.createStatement(); ResultSet rs = st.executeQuery("select name,email,message from guestbook");%> Visitor: '> Guest book is empty. <%} } finally {conn.close();} } catch (Exception e) {%> Server error: New Message Your Name E-mail Message nameemailmessage nameemailmessage pst.setString(1,request.getParameter(“name”); Your Name pst.setString(1,request.getParameter(“email”); pst.setString(1,request.getParameter(“message”); E-mail Message ?,?,? Visitor: Schema-related expressions are clustered by operation select.jspdoInsert.jsp insertForm.jsp Constructing SQL select statement Constructing SQL insert statement Rendering guest book messages as HTML table Rendering HTML form for inserting a message XP1 XP2 XP4 1. Substitute clusters with schema-shy extension points To unweave inter-crosscutting we… 2. Specify schema-related code in a separate module <%try{ Class.forName("org.gjt.mm.mysql.Driver").newInstance(); java.sql.Connection conn; conn = DriverManager.getConnection( "jdbc:mysql://localhost/database?user=login&password=pass"); try { PreparedStatement pst = conn.prepareStatement( (“insert into guestbook (name,email,message) values (?,?,?)”); pst.setString(1,request.getParameter(“name”); pst.setString(2,request.getParameter(“email”); pst.setString(3,request.getParameter(“message”); pst.execute(); %> Message was successfully added } finally {conn.close();} } catch (Exception e) {%> Server error: <%try{ Class.forName("org.gjt.mm.mysql.Driver").newInstance(); java.sql.Connection conn; conn = DriverManager.getConnection( "jdbc:mysql://localhost/database?user=login&password=pass"); try { Statement st = conn.createStatement(); ResultSet rs = st.executeQuery("select name,email,message from guestbook");%> Visitor: '> Guest book is empty. <%} } finally {conn.close();} } catch (Exception e) {%> Server error: New Message Your Name E-mail Message XP1 XP2 XP3 XP4 Abstract application Schema Weaver XP3 3. Employ weaver to produce executable code XP Model SOLUTION SOLUTION
23
Unweaving intra-crosscutting Resource Model Controller View HTTP request response Action classes JSP pages Controller servlet Web-application Selects action class to handle request received Performs server-side operations. Deposit results in web-tier containers. Selects appropriate JSP view Obtains data from web-tier containers and renders the HTTP response Structure concern cuts across action classes and JSP views
24
DDD model SOLUTION SOLUTION DDD = MVC + XP What about having one model that solves both problems?
25
Solution space SOLUTION SOLUTION ProblemModelFramework Intra- crosscutting MVCApache Struts Inter- crosscutting XPWebJinn/XP Intra- and Inter- crosscutting DDDWebJinn
26
WebJinn Architecture Resource Model Controller View request response Java classes JSP pages Controller servlet Schema SOLUTION SOLUTION
27
Benefits of WebJinn Decreased dependency between developer groups Adaptability to schema changes High code reusability. Web components! SOLUTION SOLUTION
28
Dynamic page DDD evolution Conclusion CONCLUSION CONCLUSION Intra- crosscutting Inter- crosscutting Static page CGI scripts MVC XP
29
Future Work and Projects Web AOP Project AOP language design Implementation of language semantics Weaver implementation Documentation Web components project Webjinn Component builder (use BeanBox) Eclipse plugin development Related projects: Content Management System.
30
Related Models & Frameworks Apache Struts Java Server Facets The MVC Model JSP & Servlet technology ASP, PhP and other dynamic page technologies RELATED WORK
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.