Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống
1
/ 17 trang
THÔNG TIN TÀI LIỆU
Thông tin cơ bản
Định dạng
Số trang
17
Dung lượng
385,9 KB
Nội dung
Buildingmultitiersprogram Week 9 Contents 1. Review OOP 2. Three-tier application 3. Implementing 3-tier Slide 2 Create class Add new class: menu Project->Add Class Create properties for a class Create methods for a class Create events for class Slide 3 Creating properties for a class Declare all variables in a class as private (encapsulation) private properties must be assigned values and can be get values through get/set public dataType myProperty { get { return propertyName; } set { propertyName = value; } } Slide 4 Creating methods: Write constructors A constructor is a special method that used to initialize the properties of the object A constructor is invoked when the object gets instantiated Note to write a constructor: The name of the constructor and the name of the class are the same A constructor does not return value, not even void A class can have multiple constructors (overloaded constructors) public ClassName (parameterList) { } Instantiating an object To instantiate an object, using the new keyword Example: Lop l = new Lop(); Lop c; c = new Lop(“NCTH2K”, “Cao dang nghe 2K”); Slide 6 ClassName object = new ClassName (…); ClassName object; object = new ClassName (…); Using properties, methods of a class Call methods or properties of a class Using dot operator Get/set methods: get: variable = object.propertyName set: object.propertyName = variable Example: SinhVien sv = new SinhVien(); sv.HoTen = “Nguyen Van An”; sv.DiemLT = 5; sv.DiemTH = 10; lblTB.Text = sv.DiemTB().ToString(); MessageBox.Show(sv.HoTen + “ có ĐTB = ” + sv.DiemTB()); Slide 7 Contents 1. Review OOP 2. Three-tier application 3. Implementing 3-tier Slide 8 2. Three-tier application 2.1 What is a 3-tier architecture? 2.2 What is the need for dividing the code in 3-tiers? 2.3 Designing 3-tier Slide 9 2.1 What is a 3-tier architecture? Three-tier (layer) is a client-server architecture in which the user interface, business rules and data access are developed and maintained as independent modules There are: Tier 1: Presentation tier Tier 2: Business Logic tier Tier 3: Data Access tier Slide 10 . Building multitiers program Week 9 Contents 1. Review OOP 2. Three-tier application 3. Implementing