For the past year or so, I've been focusing my attention on the Microsoft? .NET common language runtime platform. In my opinion, most new development will target this platform because it makes application development so much easier and faster. I also expect existing application development to move toward .NET at a rapid pace.
在过去的一年里,我一直注意微软的.NET通用语言运行库平台。在我看来,大多数新的开发将转到这个平台,因为他将使开发变得非常简单而快速。我也希望现有的开发也尽快转移到.NET。
To help developers embrace this new platform, my next few columns will focus on various programming issues specific to .NET. I'll assume that you are already familiar with object-oriented programming concepts. Each column will focus on run-of-the-mill programming topics that are specific to the common language runtime. All .NET developers must become aware of these topics.
为了帮助开发者理解这个新平台,我的下几个专栏将着重讲述各种.NET编程问题。我假定你已经熟悉面向对象编程概念。每个专栏将针对一般的通用语言运行库的编程问题。所有的开发者必须了解这些问题。
When showing code examples, I had to choose one of the many languages that support the .NET common language runtime. The most neutral language to choose would have been intermediate language (IL) assembly. However, it is unlikely that IL assembly will be the most popular language, so I've decided to use C#. C# is the new language that Microsoft designed specifically for the development of managed code. While the sample code shown is C# and the explanations are geared toward coding with C#, the concepts discussed are those exposed by the common language runtime and therefore apply to any language that targets it.
在给出编程示例的时候,我需要从.NET通用语言运行库支持的编程语言里来选择一种。最应该选择的是中间汇编语言。然而,遗憾的是它不是最流行的语言,所以我选择C#。C#是一种新语言,微软专门为了开发受控制代码而设计的。虽然示例是用C#的,并且解释也是针对C#的,但讨论的概念却是适合所有使用通用语言运行库的编程语言的。
My goal is to introduce various programming topics and to give you some idea of how they're implemented. It is not my goal to fully describe each topic and all the nuances that surround it. For complete details on any topic presented, please refer to the common language runtime or language documentation. Now, with the introduction out of the way, let's begin….
我的目的是介绍各种编程问题,并且给大家一些有关他们是如何实现的知识。
True Object-oriented Design
真正的面向对象设计
For programmers using the Win32? SDK, access to most of the operating system features is through a set of standalone functions exported from DLLs. These standalone functions are very easy to call from non-object-oriented languages like C. However, it is quite daunting for new developers to face literally thousands of independent functions that, on the surface, seem unrelated. Making things more difficult is the fact that many functions start with the word Get (for example, GetCurrentProcess and GetStockObject). In addition, the Win32 API has evolved over the years and Microsoft has added new functions having similar semantics but offering slightly different features over the earlier functions. You can usually identify the newer functions because their names are similar to the original function's name (such as CreateWindow/CreateWindowEx, CreateTypeLib/CreateTypeLib2, and one of my personal favorites: CreatePen/CreatePenIndirect/ExtCreatePen).
对于使用Windows 2000 SDK 的程序员,都是通过一系列独立的从DLL引出的函数来访问大多数操作系统特性的。这些孤立函数在非面向对象语言如C都可以很容易地调用。然而,令新的开发者比较头疼的是要面对许多表面上看似独立的不相干的函数。但实际上许多函数之间有复杂的关系,比如有很多函数以单词Get(例如:GetCurrentProcess 和 GetStockObject)开头。另外,Win32API发展了很多年了,微软加了一些新函数,看上去名字很象但使用上同早期的函数有细微的差别。你可能经常会把一个新的函数看成和老的一样仅因为名字很象(比如:CreateWindow/CreateWindowEx, CreateTypeLib / CreateTypeLib2, CreatePen / CreatePenIndirect / ExtCreatePen)。
All of these issues have given programmers the impression that developing for Windows? is difficult. With .NET, Microsoft is finally addressing developers' cries for help by creating an entirely object-oriented platform. Platform services are now divided into individual namespaces (such as System.Collections, System.Data, System.IO, System.Security, System.Web, and so on), and each namespace contains a set of related class typ