Download presentation
Presentation is loading. Please wait.
Published byBaldric Mosley Modified over 9 years ago
1
Architectures Classic Client/Server Architecture Classic Web Architecture N-tier (multi-tier) Architecture FEN 2014-05-021Databaser og Modellering
2
FEN 2014-05-02Databaser og Modellering2 Classic Client/Server Architecture Client: User interface (presentation) (and maybe some business logic). Application: Business logic and calls to the database server. Database server: For instance some SQL-based DBMS. DB Database Server Application Server Dedicated Client
3
FEN 2014-05-02Databaser og Modellering3 Classic Web Architecture Web server: Accesses the database server and generates HTML response to the client. Browser: Presentation (and maybe some business logic in form of scripts embedded in the HTML) Web Server Browser Client Internet DB Database Server Application Server Dedicated Client Client: User interface (presentation) (and maybe some business logic). Application: Business logic and calls to the database server. Database server: For instance some SQL-based DBMS.
4
FEN 2014-05-02Databaser og Modellering4 Problems with the Classic Web Architecture Web Server Browser Client Internet DB Database Server Application Server Dedicated Client Much business logic (code) is duplicated in the web server. No re-use. Difficult maintenance. And what if we want to add a new client (a smart phone, for instance)?
5
FEN 2014-05-02Databaser og Modellering5 N-tier (multi-tier) Architecture Web Server Browser Client Internet Dedicated Client Database access layer: All code to access database is here. Makes it possible to change data store. Web server accesses application layer – not the database directly. Easier maintenance: No business logic in the web server (or other clients). Application server: All (almost) business logic is re- used. New client may be added without code duplication. DB Database Server Application Server Database Access Layer Backend New Dedicated Client Mobile Client Client accessing web services
6
Sample Application - Architecture Architecture: – The Controller is responsible for communication with the database connection classes (DBLayer). – The DBLayer encapsulates the code for accessing the database and stores and builds objects. – The DBLayer takes the role of containers. View Code FEN 2014-05-02Databaser og Modellering6 SQL Server
7
Architecture – in Visual Studio One Solution – 5 projects, each project having its own namespace. Architecture: – Model: (old Banking4). The controller is put in its own project: Controller. – Banking5 is the old GUI. – The DBLayer has classes for accessing the database and storing and building objects. – BankingWithFullMonty is the main project with the new start-up form FEN 2014-05-02Databaser og Modellering7
8
DBLayer We use a SQL Server Database. The Class AccessDbSQLClient is responsible for opening and closing the connection and for creating a Command object that can be passed to the SQL Server. The class CustomerDBSQLClient is responsible for retrieving and storing Customer objects in the database. FEN 2014-05-02Databaser og Modellering8
9
The Controller Old implementation using lists is changed Instead we use calls to the database. FEN 2014-05-02Databaser og Modellering9 //public void AddCustomer(Customer c) //{ // customers.Add(c); //} public void AddCustomer(Customer c) { CustomerDBSQLClient.CreateCustomer(c.CustNo, c.Name); } //public List Customers //{ // get { return customers; } //} public List Customers { get { return CustomerDBSQLClient.GetCustomers(); } }
10
The Controller Complex search loops are replaced by calls to the database. FEN 2014-05-02Databaser og Modellering10 //public Customer GetCustomer(int no) //{ // //if customer not found, null is returned // Customer c = null; // int i = 0; // bool found = false; // while (!found && i < customers.Count) // { // c = customers[i]; // if (c.CustNo == no) // found = true; // else // i++; // } // return c; //} public Customer GetCustomer(int no) { return CustomerDBSQLClient.FindCustomerByNo(no); }
11
class CustomerDBSQLClient FEN 2014-05-02Databaser og Modellering11 public static Customer FindCustomerByNo(int custNo) { string sql = @"select * from Customer where custNo = " +custNo; dbCmd = AccessDbSQLClient.GetDbCommand(sql); IDataReader dbReader; dbReader = dbCmd.ExecuteReader(); Customer c; if (dbReader.Read()) c = new Customer(Convert.ToInt32(dbReader["custNo"].ToString()), dbReader["name"].ToString()); else c = null; dbReader.Close(); AccessDbSQLClient.Close(); return c; } The SQL Statement is build Command object with this SQL statement is build The command is sent to the SQL Server and executed The result is returned in a reader object – The Customer object is build from the reader DB Connection is closed Eventually the Customer object is returned.
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.