1. Trang chủ
  2. » Công Nghệ Thông Tin

Building multitiers program doc

17 152 0
Tài liệu đã được kiểm tra trùng lặp

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

THÔNG TIN TÀI LIỆU

Thông tin cơ bản

Tiêu đề Building multitiers program
Trường học Not Available
Chuyên ngành Not Available
Thể loại Not Available
Năm xuất bản Not Available
Thành phố Not Available
Định dạng
Số trang 17
Dung lượng 1,68 MB

Các công cụ chuyển đổi và chỉnh sửa cho tài liệu này

Nội dung

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

Trang 1

Building multitiers program

Week 9

Trang 2

1. Review OOP

2. Three-tier application

3. Implementing 3-tier

Trang 3

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

Trang 4

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; } }

Trang 5

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 same

 A constructor does not return value, not even void

 A class can have multiple constructors (overloaded

constructors)

public ClassName (parameterList)

{ }

Trang 6

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”);

ClassName object = new ClassName (…);

ClassName object;

object = new ClassName (…);

Trang 7

Using properties, methods of a class

 Call methods or properties of a class

 Using dot operator

 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

Trang 8

1. Review OOP

2. Three-tier application

3. Implementing 3-tier

Trang 9

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

Trang 10

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

Trang 11

2- 11

Trang 12

2.2 What is the need for dividing the code in 3-tiers?

 Reusability

 E.g if we have a module that handles adding, updating, deleting and finding customers in the system, we can use it in any

other project that might involve maintaining customers

 Transformation of the system is easy

there shouldn’t be any changes required in the business layer component and in the GUI component.

 Change management of the system is easy

to update the business logic component

Trang 13

2.3 Designing 3-tiers:

Data Access layer

 The Data Access Logic component provide methods for querying and updating data (relational databases, file

system,…)

 Each Data Access Logic component typically provides

methods for inserting, deleting, updating and retrieving

operations relating to a specific business entity in the

application

 When the application contains multiple Data Access Logic components, you may use a generic data access component

to manage database connections, execute commands,…

Trang 14

2.3 Designing 3-tiers:

Data Access layer

DACommon

- conn : OleDbConnection

+ getTable( sql: string ) : DataTable

+ Update( tableUpdate : DataTable , tableName : string ):

void

Customers

- dacommon : DACommon

+ getTable() : DataTable

+ insert (fields in database) : bool

+ delete (primary fields in database) : bool

+ update (fields in database) : bool

+ find (some fields in database) : DataTable

Products

- dacommon : DACommon + getTable() : DataTable + insert (fields in database) : bool + delete (primary fields in database) : bool + update (fields in database) : bool

+ find (some fields in database) : DataTable

Trang 15

2.3 Designing 3-tiers:

Business Logic layer

 The Business Logic layer contains classes that handle the data

 Functionality

 To call Data Access Logic components to retrieve and/or update application data

 Calculations

 Validation to enforce business rules

Trang 16

2.3 Designing 3-tiers:

Presentation layer

 The Presentation layer contains the components that are required to enable user interaction with the application  User Interface

 Functionality

 Receive and send data to the business logic tier

 Restrict the types of input a user can enter

information provided by the user controls to values needed

by the underlying components

Trang 17

1. Review OOP

2. Three-tier application

3. Implementing three-tier

 Window Application

 Class Library

Slide 17

Ngày đăng: 15/03/2014, 02:20