Home > Articles > Programming > Windows Programming

This chapter is from the book

Enhancing Developer Productivity

An important design goal of the Framework Class Library is to enhance developer productivity.

It may surprise you to know that the class library primarily targets the goal of enhanced productivity not by introducing new functionality but by repackaging functionality in an object-oriented way. That is to say that, while the Framework Class Library does introduce some new features, much of the functionality exposed by the namespaces was previously available to us through the Win32 API, ActiveX controls, COM-based DLLs, and so on. Now, however, it is wrapped in a way that allows us to program at an abstracted level where we don't have to deal with the complexities and granular pieces of data required by the Win32 API. As a direct result, we only have to deal with one over-arching design pattern in our applications: one that uses and promotes components in an object-oriented environment. Moreover, the functionality is available across all of the CLR-targeted languages!

NOTE

In case you were wondering, the Framework Class Library does not replace the Win32 API. The class library still relies on the actual Win32 API classes to talk directly to the Win32 API to execute code through something called a P/invoke (platform invoke). We'll talk more about this process when we dig into the details of calling the Win32 API from your code in Appendix A, "Calling the Win32 API from Managed Code." Of course, if the .NET Framework is ported to another environment, the P/invoke code will be calling into that environment's native API.

Finding the Code That You Need

If we start to examine the ways that the class library helps to make for a more productive development experience, we can see a few things immediately. For one, the class library allows you to easily find the functionality for which you are looking. While the size of the class library may seem daunting at first, its logical presentation inside of the namespaces allows functionality to be discovered in a straightforward fashion. For instance, the System.Drawing namespace contains classes that will provide you with drawing functions. The System.IO namespace exposes classes for basic input/output operations, and so on. And inside the System.Drawing namespace, we find objects that would be familiar to any Windows graphics programmer: the Pen object, the Brush object, and so on.

With any sufficiently sized API, the task of actually locating the code or function that you need for a given task is not an inconsiderable issue. Contrast the organization of the namespaces that we have talked about thus far with the organization of the flat, monolithic namespace offered up by the Win32 API. The Win32 API has given us such gems as FindClosePrinterChangeNotification (which doesn't find anything; it closes a resource). The problem is that, as the Win32 API has grown at its core, its developers have had to be more and more creative with their function names. The ability to look at a function name and know without some research what its purpose is has started to deteriorate. To be fair, it is possible to be productive using the Win32 API from Visual Basic. It just takes some determination and a lot of reference information. The Framework Class Library is a more approachable API: Things are where you expect them to be. It appeals to the OO programmer in all of us who, after all, is just interested in simplifying software by using objects.

NOTE

We call any code that runs under the control of the .NET runtime managed code. Unmanaged code is any code that runs outside of the .NET runtime, such as the Win32 API, COM components, and ActiveX controls. Currently, the only development tool available from Microsoft for writing unmanaged code is Visual C++.

Using the Class Library

Finding the class you need is the first step; after you have found it, the Framework Class Library also makes utilizing it easy. By exposing functionality through properties and methods, we have straightforward access to features that are extremely complicated under the hood. In the true spirit of data hiding and encapsulation, we are dealing with black boxes—we neither know nor care what takes place in the box. What we do care about is that we talk to the black box in a standard and predictable way.

This element of productivity is not insignificant. Again consider the effort required to work directly with the Win32 API. Because Visual Basic was talking to an API that had a different type system, there was not a clear, one-to-one mapping between API calls and actual Visual Basic syntax. Now, due to the integral role that the Common Type System plays, all languages talk to runtime components through the same data types. This ensures that the classes in the Framework Class Library can be consumed evenly by any of the .NET languages. For the first time, Visual Basic developers have the full range of framework functionality open to them with no corresponding drop in productivity.

There is little to no disjoint when a programmer hops between language-intrinsic functions and the class library. In other words, Visual Basic developers are finally free to accomplish their application programming without jumping in and out of different coding paradigms (such as moving from procedural Win32API patterns to VB component patterns). Design patterns can remain consistent throughout your code regardless of the actual type of component being consumed. This is because the entire library was built to support object and component-based programming intrinsically—these concepts are "built-in" and not bolted on. What's more, the class library usage follows familiar design patterns for VB developers. There is no esoteric syntax required; instead, you reference the component, instantiate it, and then use its methods and properties.

Because the Framework Class Library is written in managed code that runs on top of the .NET Common Language Runtime, it reaps all of the benefits of any other piece of managed code, such as:

  • Freedom from GUIDS, hResults, and so on

  • Automatic garbage collection of unused resources and memory

  • Support for structured exception handling

Code Reuse

The holy grail of all object-oriented development, code reuse is a large part of the value of the Framework Class Library. As all code libraries are intended to do, the intent with the class library is to provide developers with a foundation for application development. If you recall the concepts of inheritance that we talked about in Chapter 3, "Object-Oriented Concepts in .NET," VB .NET programmers are free to derive any of their classes from a base class defined in one of the system namespaces (assuming, of course, that the class has not been marked as sealed—see our note on sealed classes later). These classes don't behave any differently than a class that you would write in Visual Basic .NET. In VB .NET, the Inherits keyword is all that is needed. The following code snippet shows a program inheriting from the XMLDocument class in the System.Xml namespace:

Public Class MyDOM 
Inherits System.Xml.XmlDocument 
. 
. 
. 
End Class 

In addition to using the Framework classes for inheritance, you can also simply instantiate an object directly from one of these classes, and use it—you simply reference the namespace that you need, and then dimension and instantiate an object from one of the classes in that name-space. Object instantiation will look familiar to VB developers, because this is similar to what you have done with type libraries and COM DLLs.

This code snippet shows how you can use the Imports keyword to reference a specific name-space in the class library. The DNS class contained in the System.Net.Sockets namespace is then used to instantiate an object. The code is clear and simple to read.

Imports System.Net.Sockets 
Public Class TargetServer Sub Main() 
Dim resolver As DNS = New DNS() 
. 
.
. 
     End Sub 
End Class 

NOTE

You should know that there are classes that don't allow you to inherit from them. Conversely, there are also classes that require you to inherit from them. These classes are called sealed and abstract, respectively, and are discussed in more detail in the following section.

The end result is a universal, free, logical, and component-based API that can be easily consumed by any of the .NET languages without loss of functionality.

InformIT Promotional Mailings & Special Offers

I would like to receive exclusive offers and hear about products from InformIT and its family of brands. I can unsubscribe at any time.

Overview


Pearson Education, Inc., 221 River Street, Hoboken, New Jersey 07030, (Pearson) presents this site to provide information about products and services that can be purchased through this site.

This privacy notice provides an overview of our commitment to privacy and describes how we collect, protect, use and share personal information collected through this site. Please note that other Pearson websites and online products and services have their own separate privacy policies.

Collection and Use of Information


To conduct business and deliver products and services, Pearson collects and uses personal information in several ways in connection with this site, including:

Questions and Inquiries

For inquiries and questions, we collect the inquiry or question, together with name, contact details (email address, phone number and mailing address) and any other additional information voluntarily submitted to us through a Contact Us form or an email. We use this information to address the inquiry and respond to the question.

Online Store

For orders and purchases placed through our online store on this site, we collect order details, name, institution name and address (if applicable), email address, phone number, shipping and billing addresses, credit/debit card information, shipping options and any instructions. We use this information to complete transactions, fulfill orders, communicate with individuals placing orders or visiting the online store, and for related purposes.

Surveys

Pearson may offer opportunities to provide feedback or participate in surveys, including surveys evaluating Pearson products, services or sites. Participation is voluntary. Pearson collects information requested in the survey questions and uses the information to evaluate, support, maintain and improve products, services or sites, develop new products and services, conduct educational research and for other purposes specified in the survey.

Contests and Drawings

Occasionally, we may sponsor a contest or drawing. Participation is optional. Pearson collects name, contact information and other information specified on the entry form for the contest or drawing to conduct the contest or drawing. Pearson may collect additional personal information from the winners of a contest or drawing in order to award the prize and for tax reporting purposes, as required by law.

Newsletters

If you have elected to receive email newsletters or promotional mailings and special offers but want to unsubscribe, simply email information@informit.com.

Service Announcements

On rare occasions it is necessary to send out a strictly service related announcement. For instance, if our service is temporarily suspended for maintenance we might send users an email. Generally, users may not opt-out of these communications, though they can deactivate their account information. However, these communications are not promotional in nature.

Customer Service

We communicate with users on a regular basis to provide requested services and in regard to issues relating to their account we reply via email or phone in accordance with the users' wishes when a user submits their information through our Contact Us form.

Other Collection and Use of Information


Application and System Logs

Pearson automatically collects log data to help ensure the delivery, availability and security of this site. Log data may include technical information about how a user or visitor connected to this site, such as browser type, type of computer/device, operating system, internet service provider and IP address. We use this information for support purposes and to monitor the health of the site, identify problems, improve service, detect unauthorized access and fraudulent activity, prevent and respond to security incidents and appropriately scale computing resources.

Web Analytics

Pearson may use third party web trend analytical services, including Google Analytics, to collect visitor information, such as IP addresses, browser types, referring pages, pages visited and time spent on a particular site. While these analytical services collect and report information on an anonymous basis, they may use cookies to gather web trend information. The information gathered may enable Pearson (but not the third party web trend services) to link information with application and system log data. Pearson uses this information for system administration and to identify problems, improve service, detect unauthorized access and fraudulent activity, prevent and respond to security incidents, appropriately scale computing resources and otherwise support and deliver this site and its services.

Cookies and Related Technologies

This site uses cookies and similar technologies to personalize content, measure traffic patterns, control security, track use and access of information on this site, and provide interest-based messages and advertising. Users can manage and block the use of cookies through their browser. Disabling or blocking certain cookies may limit the functionality of this site.

Do Not Track

This site currently does not respond to Do Not Track signals.

Security


Pearson uses appropriate physical, administrative and technical security measures to protect personal information from unauthorized access, use and disclosure.

Children


This site is not directed to children under the age of 13.

Marketing


Pearson may send or direct marketing communications to users, provided that

  • Pearson will not use personal information collected or processed as a K-12 school service provider for the purpose of directed or targeted advertising.
  • Such marketing is consistent with applicable law and Pearson's legal obligations.
  • Pearson will not knowingly direct or send marketing communications to an individual who has expressed a preference not to receive marketing.
  • Where required by applicable law, express or implied consent to marketing exists and has not been withdrawn.

Pearson may provide personal information to a third party service provider on a restricted basis to provide marketing solely on behalf of Pearson or an affiliate or customer for whom Pearson is a service provider. Marketing preferences may be changed at any time.

Correcting/Updating Personal Information


If a user's personally identifiable information changes (such as your postal address or email address), we provide a way to correct or update that user's personal data provided to us. This can be done on the Account page. If a user no longer desires our service and desires to delete his or her account, please contact us at customer-service@informit.com and we will process the deletion of a user's account.

Choice/Opt-out


Users can always make an informed choice as to whether they should proceed with certain services offered by InformIT. If you choose to remove yourself from our mailing list(s) simply visit the following page and uncheck any communication you no longer want to receive: www.informit.com/u.aspx.

Sale of Personal Information


Pearson does not rent or sell personal information in exchange for any payment of money.

While Pearson does not sell personal information, as defined in Nevada law, Nevada residents may email a request for no sale of their personal information to NevadaDesignatedRequest@pearson.com.

Supplemental Privacy Statement for California Residents


California residents should read our Supplemental privacy statement for California residents in conjunction with this Privacy Notice. The Supplemental privacy statement for California residents explains Pearson's commitment to comply with California law and applies to personal information of California residents collected in connection with this site and the Services.

Sharing and Disclosure


Pearson may disclose personal information, as follows:

  • As required by law.
  • With the consent of the individual (or their parent, if the individual is a minor)
  • In response to a subpoena, court order or legal process, to the extent permitted or required by law
  • To protect the security and safety of individuals, data, assets and systems, consistent with applicable law
  • In connection the sale, joint venture or other transfer of some or all of its company or assets, subject to the provisions of this Privacy Notice
  • To investigate or address actual or suspected fraud or other illegal activities
  • To exercise its legal rights, including enforcement of the Terms of Use for this site or another contract
  • To affiliated Pearson companies and other companies and organizations who perform work for Pearson and are obligated to protect the privacy of personal information consistent with this Privacy Notice
  • To a school, organization, company or government agency, where Pearson collects or processes the personal information in a school setting or on behalf of such organization, company or government agency.

Links


This web site contains links to other sites. Please be aware that we are not responsible for the privacy practices of such other sites. We encourage our users to be aware when they leave our site and to read the privacy statements of each and every web site that collects Personal Information. This privacy statement applies solely to information collected by this web site.

Requests and Contact


Please contact us about this Privacy Notice or if you have any requests or questions relating to the privacy of your personal information.

Changes to this Privacy Notice


We may revise this Privacy Notice through an updated posting. We will identify the effective date of the revision in the posting. Often, updates are made to provide greater clarity or to comply with changes in regulatory requirements. If the updates involve material changes to the collection, protection, use or disclosure of Personal Information, Pearson will provide notice of the change through a conspicuous notice on this site or other appropriate way. Continued use of the site after the effective date of a posted revision evidences acceptance. Please contact us if you have questions or concerns about the Privacy Notice or any objection to any revisions.

Last Update: November 17, 2020