第一章:什么是xpcom(1)

 

    CHAPTER 1 What Is XPCOM?

    This is a book about XPCOM. The book is written in the form of a tutorial about creating XPCOM components, but it covers all major aspects, concepts, and terminology of the XPCOM component model along the way.
 

    This chapter starts with a quick tour of XPCOM-an introduction to the basic concepts and technologies in XPCOM and component development. The brief sections in this chapter introduce the concepts at a very high-level, so that we can discuss and use them with more familiarity in the tutorial itself, which describes the creation of a Mozilla component called WebLock.

  • "The XPCOM Solution"
  • "Components"
  • "Interfaces"
  • "Factories"
  • "XPCOM Services"

 
    第一章 什么是xpcom
    这是一本关于cpcom的书。虽然本书按照指南的组织方式来讲述创建xpcom组件的事情,但是他在讲述的过程中覆盖了所有的关于xpcom组件模型的主要的情况、观点、技术。
这一章一开始就做了一个xpcom的快速浏览,介绍了xpcom和组件开发的基本的概念和技术。而指南部分则描述了关于创建mozilla组件-WebLock的事情。由于这一章的最主要的部分在一个很高的(抽象)层次上介绍了相关概念,所以在指南部分我们就可以更加熟练的讨论、使用他们。
 
  •     xpcom解决方案
  •     组件
  •     借口
  •     工厂模式
  •     xpcom服务
 
 

    The XPCOM Solution

    The Cross Platform Component Object Module (XPCOM) is a framework which allows developers to break up monolitic software projects into smaller modularized pieces. These pieces, known as components, are then assembled back together at runtime.
 

    The goal of XPCOM is to allow different pieces of software to be developed and built independently of one another. In order to allow interoperability between components within an application, XPCOM separates the implementation of a component from the interface, which we discuss in the "Interfaces" section. But XPCOM also provides several tools and libraries that enable the loading and manipulation of these components, services that help the developer write modular cross-platform code, and versioning support, so that components can be replaced or upgraded without breaking or having to recreate the application. Using XPCOM, developers create components that can be reused in different applications or that can be replaced to change the functionality of existing applications.

 

    XPCOM not only supports component software development, it also provides much of the functionality that a development platform provides, such as:

  • component management
  • file abstraction
  • object message passing
  • memory management

    We will discuss the above items in detail in the coming chapters, but for now, it can be useful to think of XPCOM as a platform for component development, in which features such as those listed above are provided.

 

     XPCOM解决方案

    xpcom是一个架构,他允许开发人员把整体、大的的软件工程分成小的模块化的片。这些片,通常称作组件,在运行的期再聚合在一起。
    
    xpcom的目标就是让组成软件的不同组件彼此之间进行独立的开发和编译。为了允许程序里组件间的相互操作,xpcom吧组件的实现代码和接口分离,我们将在"Interfaces"部分讨论这些。不过xpcom也提供了几个支持加载和控制组件的工具和库、帮助开发人员写跨平台代码的服务端程序以及支持版本控制的(功能),这样组件可以在不打断程序(开发运行或者编译)或者必须重新生成程序的前提下进行替换或者升级。使用xpcom,开发人员可以创建良好的组件,他们支持在不同程序里边重用,或者需要在已经存在的程序里边更改功能的时候直接被替换掉。
 
    xpcom不光可以支持组件软件开发,他同时也提供了开发平台所要提供的,例如:
  •     组件控制
  •     文件抽象
  •     对象间信息传送
  •     内存控制
 

    我们将在接下来的一张里讨论上述论题的细节,不过到现在为止,你最好认为,xpcom是一个组件开发平台,这个平台提供了上述所列的特征。
 
 

Gecko

    Although it is in some ways structurally similar to Microsoft COM, XPCOM is designed to be used principally at the application level. The most important use of XPCOM is within Gecko, an open source, standards compliant, embeddable web browser and toolkit for creating web browsers and other applications.

 

    XPCOM is the means of accessing Gecko library functionality and embedding or extending Gecko. This book focuses on the latter-extending Gecko-but the fundamental ideas in the book will be important to developers embedding Gecko as well.

 

    Gecko is used in many internet applications, mostly browsers. The list includes devices such as the Gateway/AOL Instant AOL device and the Nokia Media Terminal. Gecko is also used in the latest Compuserve client, AOL for Mac OS X, Netscape 7, and of course the Mozilla client. At this time, Gecko is the predominant open source web browser.

 
 

Gecko

    虽然在某些方面,他跟微软的com在结构上有些相似,但xpcom是为了主要在应用层运行而设计的。Gecko是一个开源的,兼容标准的,嵌入式浏览器,他同时也是创建web浏览器和其他程序的工具包。对于xpcom最重要的事情就是他运行在Gecko(平台)里。
    
    xpcom是访问Gecko library提供的功能、使用嵌入的Gecko或者扩展Gecko(所要采用的)方法和手段。虽然这本书的焦点在于后边的所讲述的扩展Gecko上,但是
 
    Gecko用在了很多网络程序、大部分的浏览器上。这个(应用)列表包含了像Gateway/AOL Instant AOL、Nokia Media Terminal这样的设备。Gecko也被用在了最新的信息服务客户端,Mac OS X AOL、Netscpe 7当然也包括Mozilla客户端上。在现在找个时候,Gecko是最具优势的开源web浏览器。
 
 

Components

    XPCOM allows you to build a system in which large software projects can be broken up into smaller pieces. These pieces, known as components, are usually delivered in small, reusable binary libraries (a DLL on Windows, for example, or a DSO on Unix), which can include one or more components. When there are two or more related components together in a binary library, the library is referred to as a module.

    Breaking software into different components can help make it less difficult to develop and maintain. Beyond this, modular, component-based programming has some well-known advantages, as Table 1 describes:

TABLE 1. Benefits from Modular Code
Benefit Description
Reuse Modular code can be reused in other applications and other contexts
Updates You can update components without having to recompile the whole application
Performance When code is modularized, modules that are not necessary right away can be "lazy loaded", or not loaded at all, which can improve the performance of your application.
Maintenance Even when you are not updating a component, designing your appication in a modular way can make it easier for you to find and maintain the parts of the application that you are interested in.

 
    Mozilla has over four million lines of code, and no single individual understands the entire codebase. The best way to tackle a project of this size is to divide it into smaller, more managable pieces, use a component programming model, and to organize related sets of components into modules. The network library, for example, consists of components for each of the protocols, HTTP, FTP, and others, which are bundled together and linked into a single library. This library is the networking module, also known as "necko."
 

    But it's not always a good idea to divide things up. There are some things in the world that just go together, and others that shouldn't be apart. For example, one author's son will not eat a peanutbutter sandwich if there isn't jam on it, because in his world, peanut butter and jam form an indelible union. Some software is the same. In areas of code that are tightly-coupled-in classes that are only used internally, for example-the expensive work to divide things may not be worth the effort.

 

    The HTTP component in Gecko doesn't expose private classes it uses as separate components. The "stuff" that's internal to the component stays internal, and isn't exposed to XPCOM. In the haste of early Mozilla development, components were created where they were inappropriate, but there's been an ongoing effort to remove XPCOM from places like this.

 

 

组件

     xpcom允许你构建一个系统,在其中大型的软件工程可以被分成小的块。这些块,通常称之为组件,通常以小的、可重用的二进制库的方式出现(例如windows里边的dll,或者unix上的DSO),他们可以包含一个或者个多个组件。当一个library中有两个或者多个相关的组建的时候,这个library提及的时候成为模块。
 
    把软件分成不同的组件可以帮助(人们)降低开发和维护的难度。除此之外,模块话的,基于组件的编程有很多有名的有点,如下表所示:
    
    
TABLE 1. 模块化代码的优点
Benefit Description
Reuse 模块化的代码可以在其他的程序和环境中重用
Updates 你不用重新编译程序就能更新组件
Performance

当代码模块化以后,模块可以不用立即加载,可以"缓加载",或者根本不加在,这样可以改善你的程序的性能

Maintenance

即便是你不更新组件,用一个模块化的方法设计你的程序可以让你更简单的找到和维护程序中你感兴趣的部分。

 
    mozilla有超过4百万行的代码,没有谁能够理解整个的代码库。处理这中规模的库的最好的方法就是把它分成更小的、更容易维护的块,用组件编程模型,并且把相关联的组件集合组织为模块。
    像network库,包含了每个协议(对应的)组件,像HTTP,FTP之类的(还有其他),他们被捆绑在一起然后作为一个库被链接。这个库就是网络模块,也被称为"necko"。
    不过把东西分开并不总是一个好主意。世界上有就应该一块走的东西,其他(各个?)部分不能被分开。举例来说,笔者的一个儿子不会吃没有果酱的花生黄油三明治,这是应为在他的世界里,花生 黄油 果酱形成了一个不可分割的整体。有些软件也是一样。

未完待续.................

你可能感兴趣的:(application,performance,library,Nokia,mozilla,Components)