forums中的皮膚功能分析

來源:互聯網
上載者:User
 

因為forum使用自訂的伺服器控制項(.cs),所有有外觀的自訂伺服器控制項都繼承自SkinnedForumWebControl.cs類,在SkinnedForumWebControl.cs類的LoadSkin方法中動態裝載使用者控制項(ascx),這就提供了一種機會,使得可以根據使用者的個人配置從不同的檔案夾中裝載使用者控制項,並且在使用者控制項(ascx)中所有的圖片以及可變的外觀屬性都是使用Globals.GetSkinPath() + "/images的方式擷取的,所以我們只看到在default目錄下有完全的字檔案夾skins,其他的皮膚目錄沒有,或者只有幾個skin檔案,這是因為如果我們不想重新布局(ascx)頁面,就使用default目錄裡的ascx檔案布局,但是頁面的顏色以及圖片等屬性則是根據使用者定義的皮膚目錄來擷取的。
這種換膚和使用不同的css有很大的區別,使用css只能改變控制項的顏色,大小等,使用動態裝載技術還能實現控制項的不同布局。就像使用xsl檔案來解釋xml呈現不同的樣式一樣。
使用來表示

看看模板方法模式,就好理解了

UML class diagram

// Template Method pattern -- Structural example
using System;

// "AbstractClass"


abstract class AbstractClass

{
  // Methods
  abstract public void PrimitiveOperation1();
  abstract public void PrimitiveOperation2();

 
// The Template method
  public void TemplateMethod()
  {
    Console.WriteLine(
                "In AbstractClass.TemplateMethod()");

    PrimitiveOperation1();
    PrimitiveOperation2();
  }
}

// "ConcreteClass"


class ConcreteClass : AbstractClass

{
  // Methods
  public override void PrimitiveOperation1()
  {
    Console.WriteLine(
        "Called ConcreteClass.PrimitiveOperation1()");

  }

  public override void PrimitiveOperation2()

  {
    Console.WriteLine(
        "Called ConcreteClass.PrimitiveOperation2()");

  }
}

/// <summary>
/// Client test
/// </summary>
public class Client
{
  public static void Main( string[] args )
  {
    // Create instance and call template method
    ConcreteClass c = new ConcreteClass();
    c.TemplateMethod();

  }

}
Output

In AbstractClass.TemplateMethod()
Called ConcreteClass.PrimitiveOperation1()
Called ConcreteClass.PrimitiveOperation2()

其實就是"抽象-具體"模式,系統需要的是一個抽象的引用,而我們提供給系統的是具體的實現方法.


聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.