1. Trang chủ
  2. » Giáo án - Bài giảng

Building Multitier Programs with Classes

33 125 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 Multitier Programs with Classes
Trường học Unknown University
Chuyên ngành Computer Science
Thể loại Lecture Notes
Năm xuất bản Unknown
Thành phố Unknown
Định dạng
Số trang 33
Dung lượng 333,07 KB

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

Nội dung

Creating Properties in a Class • Declare all variables in a class as privateencapsulation • private variable values are only available to procedures in the class • When objects are crea

Trang 1

Week 9 Building Multitier Programs with

Classes

Trang 2

2- 2

Contents

• 1 Review to OOP

– Create properties – Create methods

• 2 3-tier application

• 3.Example

• 4 Exercises

Trang 4

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

Trang 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

Trang 6

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

Trang 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

Trang 8

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

Trang 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

Trang 10

2- 10

Create method

• Subroutines

Trang 11

Throwing and Catching

• You can make an exception

• Use the try/catch block to enclose code that could cause an exception

– Exampe

Creating Classes

Trang 12

2- 12

3-tier application

• What is 3-tier model?

• Physical & logic model

• What is business tier

• Business object & original object

• Sending message between tier-s

Trang 13

2 What is 3-tier model?

• “Plug-in” new components

Applications designed in components (services) where each section performs part of the necessary actions.

Applications designed in components (services) where each section performs part of the necessary actions.

Object-Oriented Programming

Trang 14

Business Object Validation Calculations Business logic Business rules

User Services

Trang 15

What is 3-tier model?

Multitier Applications

• Presentation tier  the user interface

You can change the method of delivery without changing the processing

You can change the method of delivery without changing the processing

Trang 17

What is 3-tier model? More detail

Trang 18

• presents information to the user, and

collects user input

Trang 19

What is 3-tier model?

UI

• logic to decide what the user sees, the

navigation paths, and how to interpret user input

• accepts user input and then provides it to the business logic, where it can be

validated, processed

• In NET, UI code is almost event-driven

• Only request to middle-tier

Trang 20

2- 20

What is 3-tier model?

Business logic

• Definition from Microsoft

"The combination of validation edits, logon verifications, database lookups, policies, and algorithmic

transformations that constitute an enterprise's way of doing business".

• must reside in a separate tier from the UI code

• Request to DAL

Trang 21

What is 3-tier model?

Trang 22

2- 22

What is 3-tier model?

Data storage and management

• Database servers such as SQL Server or MS Acccess, Oracle

• physical creation, retrieval, update, and

deletion of data

Trang 23

Physical & logic model Framework Design

Trang 24

2- 24

3-tier in logic and physical

UI Win.app

UI

Middle-tier VB6, VB.Net, C#, Java

Data –tier (DAL) VB6, VB.Net, C#, Java

Data store

Server 1

Data store Server 3 Data store

Server 2

Trang 25

Physical & logic model

Single tier System

• Good for standalone environments,

• install everything on a single client

workstation

• n-tier systems can run on a single machine

Trang 27

Physical & logic model 3-tier

• can centralize all access to the

database on a single machine

Trang 28

2- 28

Business objects and Object

• Object: encapsulate, abstract entity or

Trang 29

Why using Business tier?

• Cannot assume that incoming data is valid

• Not all incoming data is from the user

• Data from the database may also be invalid

– Translated data

– Updates to data from other applications

– Errors ???

Trang 30

+Can not raise message in middle, data tier

+Can not generate SQL command in middle, UI tier

Trang 31

Example

• Hanoi tower

– Using event for message sending from business tier to UI.

• Contact phone application

– Using 2 data store: SIM & PHONE

– Using exception

• Using Class Library (Class_Library.PPT)

Trang 32

2- 32

3.Class Library

Make library for others projrct

Menu File->All new Project->Class Library From main project->Add Refference

Example

Trang 33

How to make a 3-tier app

Ngày đăng: 13/05/2014, 12:19