Enterprise Systems & Frameworks CS25010 - Web Programming Connor Goddard 5 th November 2015 Aberystwyth University 1
INTRODUCTION In today s session, we will aim to cover the following: Multi-tier Architectural Patterns Enterprise Systems Web Frameworks 2
INTRODUCTION If you re on Twitter, jump on your phones! During the presentation, look out for tweets from @cgddrd with the hashtag #cs25010. These tweets will contain links to other material you may find useful. Feel free to tweet back with any questions. 3
A LITTLE BIT ABOUT ME I m a fifth-(and final!)-year MEng Software Engineering student. Previous web modules include: CS15020, CS25010, CS25210, SE31520 & SEM5640 (so pretty much them all ) I spent my IY working at Renishaw plc, developing advanced web and mobile applications (Android, ios & hybrid) I ve played around with most web-related technologies including: PHP, ASP.NET, Node.js, Ruby-on-Rails, Python & OO-Javascript 4
WEB APPLICATIONS What do we mean by a web application? What makes a web application different to other applications? Where does the cloud fit into it all? 5
WEB APPLICATIONS To a typical consumer, web applications can appear mystical. [1] Most do not appreciate all that has to go on under the hood. What problems could this present on development projects? [1] http://imgflip.com 6
ENTERPRISE SYSTEMS When designing non-trivial web applications, we typically will want to decompose the system into smaller parts. Separate presentation from business logic and data sources. Possibly delegate across multiple servers. These are known as multi-tier/n-tier or enterprise systems. As a consequence, interconnectivity between separate systems and their servers becomes essential. 7
MULTI-TIER ARCHITECTURES Web Server Application Server Database Server [1] https://en.wikipedia.org/wiki/multitier_architecture 8
MULTI-TIER ARCHITECTURES Presentation Tier Web Server Model View Controller e.g. HTML, ASP.NET, PHP, JSP, XML, JSON Logic Tier Application Server Business Logic Business Objects Business Objects e.g. PHP, JavaBeans, C#, Ruby Data Tier Database Server RDBMS OO-DMS File Stores e.g. MySQL, PostgreSQL, MongoDB, XML 9
MULTI-TIER ARCHITECTURES Example: Online Store Presentation Layer Logic Layer Data Layer 10
MULTI-TIER ARCHITECTURES There is a distinction between tiers and layers. What is the difference between the two terms? 11
MULTI-TIER ARCHITECTURES There is a clear distinction between tiers and layers. What is the difference between the two terms? Layer: Logical organisation/separation of code (e.g. separating code associated with presentation from that of business logic) Tier: Physical deployment of layers (e.g. across multiple servers) 12
MULTI-TIER ARCHITECTURES Why would we want to use multi-tier systems? What would be the advantages? What would be the disadvantages? 13
MULTI-TIER ARCHITECTURES Why would we want to use multi-tier systems? Advantages: Separation of concerns Improved scalability Help to avoid single point of failure Improved problem solving/bug tracking (isolation of issues to specific part of system) Easier mapping of system entities to developer workload Disadvantages: Could prove to be overkill for very small projects Likely increase in code size and complexity Steeper learning curve - greater potential for bugs to be introduced Use of M-TA introduces greater risk for poor design choices - these can become expensive to fix later Easier mapping of system entities to developer workload - Too many cooks spoil the broth. 14
WEB FRAMEWORKS 15
WEB FRAMEWORKS What frameworks do people know about? Has anyone got any preferred frameworks? 16
WEB FRAMEWORKS PHP Adobe Coldfusion C# / VB / F# Javascript Javascript PHP Ruby 17
WEB FRAMEWORKS Good community support Long history High feature set Fast and easy to scale Lightweight + good community support Simple to set-up Many tools out of the box 18
WEB FRAMEWORKS Frameworks aim to assist in the development of web applications by alleviating some of the overhead associated with common tasks: Database access, ORM, templates, authorisation, web services, scaffolding, testing, caching, session management etc. Web frameworks are not the same as CMS software (e.g. Wordpress or Drupal) Frameworks provide general solutions to developing web applications. CMS software builds on top of underlying frameworks. 19
SCAFFOLDING Scaffolding refers to a process whereby the skeleton of an application is automatically generated by the web framework. Typically the reference to a database is given, from which the code relating to standard CRUD operations is enacted without input from the developer. Scaffolded systems provide a good starting point from which the main application can be built upon. [1] [1] https://scaffoldinginsouthwest.wordpress.com/ 20
SCAFFOLDING - RoR One of the first mainstream frameworks to support scaffolding was Ruby-on-Rails. Generating a new web application in RoR takes 3 lines of code: 1 # Step 1: Generate new web application. 2 rails new mywebapp && cd mywebapp 3 4 # Step 2: Create new model entity and scaffold 5 CRUD operations (controller and views). 6 rails generate scaffold User surname firstname 7 age:integer is_student:boolean 8 9 # Step 3: Migrate the new model into SQLite 10 database (pre-created) 11 rake db:migrate 12 13 # Step 4: Start the server (navigate to http://<url>/users) 14 rails server 21
SCAFFOLDING - ASP.NET ASP.NET is another framework that provides automatic creation of web controllers and views from a pre-existing data model. This is particularly useful within MVC projects where we are also utilising object-relational mapping. 22
OBJECT-RELATIONAL MAPPING Object-relational mapping (ORM) provides a mechanism for representing and querying relational entities using an objectbased paradigm. In other words: ORM allows us to map data stored in a relational/tabular format into an OO format for use in applications. ORM helps to address an issue known as Object-Relational Impedance Mismatch. 23
OBJECT-RELATIONAL MAPPING Relational - Object mapping: Relational Model ORM Table Class Row Instance Field Property With ORM, it doesn t matter what persistent storage mechanism we are using (e.g. MySQL, NoSQL, XML data files etc.) The framework handles this all for us. 24
FRAMEWORKS, ORM & MVC Many frameworks adopt an MVC pattern, supported by mechanisms including scaffolding and ORM. Generated via ORM Template files used to render dynamic data to end user (e.g. HTML, XML, JSON) Class for each model responsible for: Handling incoming requests Retrieving model data Re-directing user to appropriate view templates [1] https://en.wikipedia.org/wiki/model view controller [1] 25
MVC - MODEL ASP.NET (C#) 1 namespace HelloMVC.Models 2 { 3 public class BlogPost 4 { 5 6 public virtual int Id 7 { 8 get; set; 9 10 } 11 12 public virtual string Title 13 { 14 get; set; 15 16 } 17 18 } 19 } PHP 1 <?php 2 3 class BlogPost { 4 5 public $id; 6 public $title; 7 8 public function construct($id, $title) { 9 $this->id = $id; 10 $this->title = $title 11 } 12 13 function save(); 14 function settitle(); 15... 16 17 }?> 26
MVC - CONTROLLER ASP.NET (C#) PHP 1 namespace HelloMVC.Controllers 2 { 3 public class BlogPostController : Controller 4 { 5 private HelloMVCContext db = new HelloMVCContext(); 6 7 public ActionResult Index() 8 { 9 return View(db.BlogPosts.ToList()); 10 } 11 12 public ActionResult Create() GET Request 1 <?php 2 3 class BlogController { 4 5 function indexaction(); 6 function createaction(); 7 8... 9 10 }?> 13 { 14 return View(); 15 } 16 17 [HttpPost] 18 [ValidateAntiForgeryToken] 19 public ActionResult Create([Bind(Include = "Id,Title")] BlogPost blogpost) 20 { 21 if (ModelState.IsValid) 22 { 23 db.blogposts.add(blogpost); 24 db.savechanges(); 25 return RedirectToAction("Index"); 26 } 27 28 return View(blogPost); 29 } 30 } 31 } POST Request 27
MVC - VIEW 1 @model IEnumerable<HelloMVC.Models.BlogPost> ASP.NET (Razor) 2 3 @{ 4 ViewBag.Title = "Blog Posts"; 5 } 6 7 <h2>list of Posts</h2> 8 9 <ul> 10 @foreach (var item in Model) { 11 12 13 <li> 14 <a href="@html.actionlink("details", "Details", new { id=item.id })"> 15 @Html.DisplayFor(modelItem => item.title) 16 </a> 17 </li> 18 } 19 20 </ul> PHP 1 {% block title %}Blog Posts{% endblock %} 2 3 {% block body %} 4 5 <h2>list of Posts</h2> 6 7 <ul> 8 {% for item in blog_posts %} 9 <li> 10 <a href="{{ path('blog_show', {'id': post.id}) }}">{{ post.title }}</a> 11 </li> 12 {% endfor %} 13 </ul> 14 15 {% endblock %} 28
APPLICATION SERVERS Of course, once we have developed our web application, we need to be able to host and run it. Application Server: Software designed to handle communication between a front-end website, and a business back-end system. Features include: Performance optimisation (caching, profiling etc.) Database management (population, transactions etc.) Load Balancing Logging/Debugging Security Data integrity support Deployment Recovery management (application isolation) 29
APPLICATION SERVERS Application servers provide services and features appealing for enterprise systems. Remember: Enterprise systems imply large volumes of data, high potential for scalability and co-ordination of business processes across multi-tier architecture. [1] [1] http://maaw.info/articlesummaries/artsumdavenport98.htm 30
APPLICATION SERVERS Glassfish (Oracle) JavaEE IIS (Microsoft) ASP.NET Wildfly (Red Hat) Java Zend Server PHP Tomcat (Apache) Java Servlets & JSP 31
IDEAS FOR ASSIGNMENT While use of frameworks and multi-tier architectures is not an explicit requirement for the assignment, you could always investigate their use for your own learning plus perhaps for some extra marks (cough cough) Ideas to consider include: Database management functions Templates/server-side includes ORM 32
Many thanks for your time. Questions? @cgddrd clg11@aber.ac.uk http://cgddrd.me 33