Introduction to ASP.NET

Download Report

Transcript Introduction to ASP.NET

Business Object
Payne Ch. 15
MIS 424
Professor Sandvig
Overview
What are business objects
Benefits
How to Create
How to use

2 examples
Usage Tips
What are Business Objects
Extensions of .NET class library
Create new classes



Properties
Methods
Events
Web site


Presentation  User Controls
Code/logic  Business Objects
Benefits of Business Objects
Key element of OOP


Encapsulation
Reusability
N-tier application development
Compiled

Protect proprietary code (sort of)
Mix & match languages

.aspx pages, different components
How to Create
Steps:
1. Create new class file



.vb (or .cs) extension
App_code directory
Contains class functionality
2. Call new class from .aspx file
3. Test in VS 2005
4. Upload .vb and .aspx files to server
1. Creating Class file
1. Create file with .vb extension in folder
App_Code
2. Import need libraries
Not part of .aspx page
3. Define Namespace
4. Define class
5. Write code for the class
Example: SimpleQuote.vb
2. Call from .aspx page
Import Namespace


New class is part of Application’s class library
Just like other classes in .NET library
Instantiate class
Example:

SimpleQuote.aspx code, output
Example 2: Calculator
Pass in properties

Declare as public variables
Example:


SimpleCalculator.vb code
SimpleCalculator.aspx code, output
Usage Tips
When to Use Business Objects

Subjective
Opinion 1: all business logic

Business Layer
Opinion 2: Only reusable code
Usage Tips
Debugging

No response.write in BOs
Write & debug code with:



VS 2005 or
Visual Web Developer or
Dreamweaver
Bugs in ANY BO can disable entire application.
Summary
Goal of Business objects


Encapsulation
Reusability
When to use

Large programs
Modularity


Code used > 1
Web Services