Tải bản đầy đủ (.ppt) (17 trang)

Building multitiers program doc

Bạn đang xem bản rút gọn của tài liệu. Xem và tải ngay bản đầy đủ của tài liệu tại đây (284.45 KB, 17 trang )

Building multitiers program
Building multitiers program
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
2- 11
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

E.g. if we are moving from SQL Server data storage to Oracle
there shouldn’t be any changes required in the business layer
component and in the GUI component.

Change management of the system is easy

E.g. if GST (TAX) is changed from 10% to 15% we only need
to update the business logic component
Slide 12
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,…
2.3 Designing 3-tiers:
Data Access layer
DACommon
- conn : OleDbConnection
+ getTable( sql: string ) : DataTable
+ Update( tableUpdate : DataTable , tableName : string ):
void
Slide 14
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

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


Acquire data from users

Restrict the types of input a user can enter

Perform simple mapping and transformations of the
information provided by the user controls to values needed
by the underlying components
Contents
1. Review OOP
2. Three-tier application
3. Implementing three-tier

Using single Project

Using multiple Project:

Window Application

Class Library
Slide 17

Tài liệu bạn tìm kiếm đã sẵn sàng tải về

Tải bản đầy đủ ngay
×