Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống
1
/ 33 trang
THÔNG TIN TÀI LIỆU
Thông tin cơ bản
Định dạng
Số trang
33
Dung lượng
333,07 KB
Nội dung
Week 9 BuildingMultitierProgramswithClasses 2- 2 Contents • 1. Review to OOP – Create properties – Create methods • 2. 3-tier application • 3.Example • 4. Exercises 2- 3 1. Review OOP • Create class – Menu Project->Add Class – Chage class name – Make properties – Make methods – Make events 2- 4 1. Creating Properties in a Class • Declare all variables in a class as private (encapsulation) • private variable values are only available to procedures in the class • When objects are created from a class, values must be assigned values and values must be passed from the class Creating Classes Creating Classes 2- 5 A Read-Only Property class Myclass { private int myVar=0; public int MyProperty { get { return myVar; } } } class Myclass { private int myVar=0; public int MyProperty { get { return myVar; } } } Creating Classes Creating Classes 2- 6 Constructors • • initializes an object when created. • Same name as its class • similar to a method. • have no explicit return type. A constructor is a method that automatically executes when an object is instantiated. A constructor is a method that automatically executes when an object is instantiated. Creating Classes Creating Classes 2- 7 Constructors with parameters • for some situations, we need a constructor that accepts parameters. • Parameters are added to a constructor in the same way that they are added to a method Creating Classes Creating Classes 2- 8 Overloading the Constructor class Myclass { public Myclass(int input) { this.myVar = input; } public Myclass() { this.myVar = 200; } } class Myclass { public Myclass(int input) { this.myVar = input; } public Myclass() { this.myVar = 200; } } Two methods have the same name but a different list of arguments Two methods have the same name but a different list of arguments A signature is the argument list of a method or procedure A signature is the argument list of a method or procedure Creating Classes Creating Classes 2- 9 Retrieving shared Variables • When placed on a static keyword, the keyword makes values accessible without instantiating the object of the class class Myclass { private static int myVar=0; public static int MyProperty { get { return myVar; } } } class Myclass { private static int myVar=0; public static int MyProperty { get { return myVar; } } } Creating Classes Creating Classes 2- 10 Create method • Subroutines [...]... Object-Oriented Programming 2- 14 Data Services Data Retrieval Data storage What is 3-tier model? Multitier Applications • Presentation tier the user interface You can change the You can change the method of delivery without method of delivery without changing the processing changing the processing 2- 15 What is 3-tier model? Multitier Applications • Data tier retrieving and storing the data in a database • Business... Use the try/catch block to enclose code that could cause an exception – Exampe 2- 11 Creating Classes Creating Classes 3-tier application • • • • • 2- 12 What is 3-tier model? Physical & logic model What is business tier Business object & original object Sending message between tier-s 2 What is 3-tier model? Multitier Applications in components Applications designed in components Applications designed... Three-tier applications are popular – Presentation tier – Business tier – Data tier • Goal is to write components that can be replaced without replacing other components • “Plug-in” new components Object-Oriented Programming Object-Oriented Programming 2- 13 What is 3-tier model? Multitier Applications User Services User Interface Forms Controls Menus Business Services Business Object Validation Calculations... concurrent users with SQL Server 2- 26 Physical & logic model 3-tier • can centralize all access to the database on a single machine • connection pooling • 150-200 concurrent users =>2 or 3 database connections • can support thousands of concurrent users 2- 27 Business objects and Object • Object: encapsulate, abstract entity or concept • Business object: encapsulate our data along with its related... algorithmic transformations that constitute an enterprise's way of doing business" • must reside in a separate tier from the UI code • Request to DAL 2- 20 What is 3-tier model? Data access • interacts with the data management tier to retrieve, update, and remove information • Data access tier doesn't actually manage or store the data • Provides an interface between the business logic and the database... Calculations – Validation to enforce business rules Object-Oriented Programming Object-Oriented Programming 2- 16 What is 3-tier model? More detail 2- 17 What is 3-tier model? Presentation • some GUI forms with which the user can interact • presents information to the user, and collects user input 2- 18 What is 3-tier model? UI • logic to decide what the user sees, the navigation paths, and how to interpret