剖析ASP.NET AJAX的面向?qū)ο笏枷?3)_.Net教程
推薦:ASP.NET緩存:方法分析和實(shí)踐示例盡早緩存;經(jīng)常緩存 您應(yīng)該在應(yīng)用程序的每一層都實(shí)現(xiàn)緩存。向數(shù)據(jù)層、業(yè)務(wù)邏輯層、UI 或輸出層添加緩存支持。內(nèi)存現(xiàn)在非常便宜 — 因此,通過以智能的方式在整個(gè)應(yīng)用程序中實(shí)現(xiàn)緩存,可以
Inheritance.js腳本文件中定義了兩個(gè)類:Person和Employee,Employee是從Person繼承而來。每個(gè)類都有字段、公共屬性和方法。另外,Employee類重寫了toString的實(shí)現(xiàn),并在重寫的代碼中調(diào)用了基類的功能。在這個(gè)例子中把類Person的名字空間設(shè)定為"Demo"。運(yùn)行頁面Inheritance.aspx,點(diǎn)擊“創(chuàng)建對(duì)象”、“對(duì)象釋放”、“公共和私有屬性”、“對(duì)象方法”、“重寫方法”,“對(duì)象類型檢查”體驗(yàn)一下。
4.接口
接口是類要實(shí)現(xiàn)的邏輯協(xié)議,是對(duì)類進(jìn)行集成的公共遵守的規(guī)范。它能使多個(gè)類和同一個(gè)接口把實(shí)現(xiàn)定義和類的具體實(shí)現(xiàn)結(jié)合起來。下面的例子定義了一個(gè)基類Tree和接口IFruitTree,Apple和Banana這兩個(gè)類實(shí)現(xiàn)了接口IFruitTree,但Pine類沒有實(shí)現(xiàn)接口IFruitTree。
| Type.registerNamespace("Demo.Trees");
Demo.Trees.IFruitTree = function() {} Demo.Trees.IFruitTree.Prototype = { bearFruit: function(){} } Demo.Trees.IFruitTree.registerInterface('Demo.Trees.IFruitTree'); Demo.Trees.Tree = function(name) { this._name = name; } Demo.Trees.Tree.prototype = { returnName: function() { return this._name; }, toStringCustom: function() { return this.returnName(); }, makeLeaves: function() {} } Demo.Trees.Tree.registerClass('Demo.Trees.Tree'); Demo.Trees.FruitTree = function(name, description) { Demo.Trees.FruitTree.initializeBase(this, [name]); this._description = description; } Demo.Trees.FruitTree.prototype.bearFruit = function() { return this._description; } Demo.Trees.FruitTree.registerClass('Demo.Trees.FruitTree', Demo.Trees.Tree, Demo.Trees.IFruitTree); Demo.Trees.Apple = function() { Demo.Trees.Apple.initializeBase(this, ['Apple', 'red and crunchy']); } Demo.Trees.Apple.prototype = { makeLeaves: function() { alert('Medium-sized and desiduous'); }, toStringCustom: function() { return 'FruitTree ' Demo.Trees.Apple.callBaseMethod(this, 'toStringCustom'); } } Demo.Trees.Apple.registerClass('Demo.Trees.Apple', Demo.Trees.FruitTree); Demo.Trees.GrannySmith = function() { Demo.Trees.GrannySmith.initializeBase(this); // You must set the _description feild after initializeBase // or you will get the base value. this._description = 'green and sour'; } Demo.Trees.GrannySmith.prototype.toStringCustom = function() { return Demo.Trees.GrannySmith.callBaseMethod(this, 'toStringCustom') ' ... its GrannySmith!'; } Demo.Trees.GrannySmith.registerClass('Demo.Trees.GrannySmith', Demo.Trees.Apple); Demo.Trees.Banana = function(description) { Demo.Trees.Banana.initializeBase(this, ['Banana', 'yellow and squishy']); } Demo.Trees.Banana.prototype.makeLeaves = function() { alert('Big and green'); } Demo.Trees.Banana.registerClass('Demo.Trees.Banana', Demo.Trees.FruitTree); Demo.Trees.Pine = function() { Demo.Trees.Pine.initializeBase(this, ['Pine']); } Demo.Trees.Pine.prototype.makeLeaves = function() { alert('Needles in clusters'); } Demo.Trees.Pine.registerClass('Demo.Trees.Pine', Demo.Trees.Tree); |
Interface.js腳本文件中定義了一個(gè)Tree基類和一個(gè)IFruitTree接口。Apple和Banana兩個(gè)繼承類實(shí)現(xiàn)了IFruitTree接口,而Pine類沒有實(shí)現(xiàn)IFruitTree接口。運(yùn)行Interface.aspx,點(diǎn)擊“對(duì)象創(chuàng)建”、“接口檢查”、“調(diào)用接口方法”體驗(yàn)一下。
5.枚舉
枚舉是包含一組被命名的正整數(shù)常數(shù)的類。你可以像訪問屬性一樣訪問它的值。例如:
myObject.color = myColorEnum.red,枚舉提供了一種很容易理解的整數(shù)表示。下面的例子定義了一個(gè)以十六進(jìn)制數(shù)表示的顏色被命名為有意義的名字的枚舉類型。
運(yùn)行Enumeration.aspx,選擇下拉框中的顏色,腳本程序把背景色設(shè)為選中的枚舉類型Demo.Color中的顏色。
6.反射
反射用于檢查一個(gè)運(yùn)行期程序的結(jié)構(gòu)和組成,是通過類Type的API來實(shí)現(xiàn)反射的,這些方法使你能夠收集一個(gè)對(duì)象的信息,例如:它是繼承于哪個(gè)類、它是否實(shí)現(xiàn)類某個(gè)特指的接口、它是否是某個(gè)類的實(shí)例等。
下面的例子用反射的API測試GrannySmith類是否實(shí)現(xiàn)了前面的接口。運(yùn)行Reflection.aspx,點(diǎn)擊“檢查類型”、“檢查繼承”、“檢查接口”體驗(yàn)一下。
另外需要說明的一點(diǎn)是,Microsoft AJAX Library是基于開放體系架構(gòu)而開發(fā)的,不僅僅用于asp.net,還能用于其它體系架構(gòu)中,例如用在java中。
分享:Asp.Net中動(dòng)態(tài)頁面轉(zhuǎn)靜態(tài)頁面關(guān)于在Asp.Net中動(dòng)態(tài)頁面轉(zhuǎn)靜態(tài)頁面的方法網(wǎng)上比較多。結(jié)合實(shí)際的需求,我在網(wǎng)上找了一些源代碼,并作修改�,F(xiàn)在把修改后的代碼以及說明寫一下。 一個(gè)是一個(gè)頁面轉(zhuǎn)換的類,該類通過靜態(tài)函數(shù)Ch
- asp.net如何得到GRIDVIEW中某行某列值的方法
- .net SMTP發(fā)送Email實(shí)例(可帶附件)
- js實(shí)現(xiàn)廣告漂浮效果的小例子
- asp.net Repeater 數(shù)據(jù)綁定的具體實(shí)現(xiàn)
- Asp.Net 無刷新文件上傳并顯示進(jìn)度條的實(shí)現(xiàn)方法及思路
- Asp.net獲取客戶端IP常見代碼存在的偽造IP問題探討
- VS2010 水晶報(bào)表的使用方法
- ASP.NET中操作SQL數(shù)據(jù)庫(連接字符串的配置及獲取)
- asp.net頁面?zhèn)髦禍y試實(shí)例代碼
- DataGridView - DataGridViewCheckBoxCell的使用介紹
- asp.net中javascript的引用(直接引入和間接引入)
- 三層+存儲(chǔ)過程實(shí)現(xiàn)分頁示例代碼
.Net教程Rss訂閱編程教程搜索
.Net教程推薦
- 淺析8月編程語言榜:.Net前景如何?
- 教你簡單方便獲取Web設(shè)計(jì)的免費(fèi)資源
- 對(duì)C#中正則表達(dá)式的一些解讀和總結(jié)
- 如何用.NET讀取 Flash格式文件信息
- 關(guān)于.NET 4.0改進(jìn)的介紹
- .NET平臺(tái)依賴注入機(jī)制及IoC的設(shè)計(jì)與實(shí)現(xiàn)
- ASP.NET--制作功能完善的安裝程序
- .NET教程之--asp.net初學(xué)者項(xiàng)目開發(fā)疑難小結(jié)
- 利用.net的強(qiáng)大功能發(fā)送email
- 遠(yuǎn)程抓取GOOGLE的自動(dòng)翻譯結(jié)果
- 相關(guān)鏈接:
- 教程說明:
.Net教程-剖析ASP.NET AJAX的面向?qū)ο笏枷?3)
。