Đang chuẩn bị nút TẢI XUỐNG, xin hãy chờ
Tải xuống
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) | Building multitiers program Week 9 Contents Review OOP Three-tier application Implementing 3-tier Slide Create class Add new class: menu Project->Add Class Create properties for a class Create methods for a class Create events for class Slide 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 When objects are created from a class, 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 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 Contents Review OOP Three-tier application Implementing 3-tier Slide 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 Physical & Logic model What is Business tier? Business object & original object Sending message between tier 2.1 What is a 3-tier architecture? Three-tier . | Building multitiers program Week 9 Contents Review OOP Three-tier application Implementing 3-tier Slide Create class Add new class: menu Project->Add Class Create properties for a class Create methods for a class Create events for class Slide 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 When objects are created from a class, 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) { } .