Chapter 1(Part 4)Introduction to Visual Basic

Also, changes made to the system on behalf of one application will typically affect all applications on the machine–building an application today that is completely isolated from changes is not easy.

One reason why it’s hard to build an isolated application is that the current run-time environment typically allows the installation of only a single version of a component or an application. This restriction means that component authors must write their code in a way that remains backward compatible, otherwise they risk breaking existing applications when they install a new component. In practice, writing code that is forever backward compatible is extremely difficult, if not impossible.

In .NET, the notion of side-by-side is core to the versioning story. Side-by-side is the ability to install and run multiple versions of the same component on the machine at the same time. With components that support side-by-side, authors aren’t necessarily tied to maintaining strict backward compatibility because different applications are free to use different versions of a shared component.

1.3.9 Global Assembly Cache (GAC)

Each computer where the common language runtime is installed has a machine-wide code cache called the global assembly cache. The global assembly cache stores assemblies specifically designated to be shared by several applications on the computer.

You should share assemblies by installing the in to the global assembly cache only when you need to. As a general guideline, keep assembly dependencies private, and locate assemblies in the application directory unless sharing an assembly is explicitly required. In addition, it is not necessary to install assemblies into the global assembly cache to make them accessible to COM interop or unmanaged code.

There are several ways to deploy an assembly into the global assembly cache:

  • Use an installer designed to work with the global assembly cache. This is the preferred option for installing assemblies into the global assembly cache.
  • Use a developer tool called the Global Assembly Cache tool (Gacutil.exe), provided by the .NET Framework SDK.
  • Use Windows Explorer to drag assemblies into the cache.

Administrators often protect the WINNT directory using an Access Control List (ACL) to control write and execute access. Because the global assembly cache is installed in the WINNT directory, it inherits that directory’s ACL. It is recommended that only users with Administrator privileges be allowed to delete files from the global assembly cache. Assemblies deployed in the global assembly cache must have a strong name.

When an assembly is added to the global assembly cache, integrity checks are performed on all files that make up the assembly. The cache performs these integrity checks to ensure that an assembly has not been tampered with, for example, when a file has changed but the manifest does not reflect the change.

  • The Common Type System

The Common Type System defines how data types are declared, used, and managed in the runtime, and is also an important part of the runtime’s support for the Cross Language Integration. The common type system performs the following functions:

  • Establishes a framework that enables cross-language integration, type safety, and high performance code execution.
  • Provides an object-oriented model that supports the complete implementation of many programming languages.
  • Defines rules that languages must follow, which helps ensure that objects written in different languages can interact with each other.

The Common Type System can be divided into two general categories of types–Reference type and Value type each of which is further divided into subcategories.

  • Classes Notes

Class defines the operations an object can perform (methods, events, or properties) and defines a value that holds the state of the object (fields). Although a class generally includes both definition and implementation, it can have one or more members that have no implementation. An instance of a class is an object. You access an object’s functionality by calling its methods and accessing its properties, events, and fields.

Nested classes also have member characteristics. Class members that have no implementation are abstract members. A class that has one or more abstract members is itself abstract; new instances of it cannot be created.

Some languages that target the runtime allow you to mark a class as abstract even if none of its members are abstract. You can use an abstract class when you need to encapsulate a basic set of functionality that derived classes can inherit or override when appropriate. Classes that are not abstract are referred to as concrete classes.

A class can implement any number of interfaces, but it can inherit from only one base class. All classes must have at least one constructor, which initializes new instances of the class. Each language that supports the runtime provides a way to indicate that a class or class member has specific characteristics. When you use the syntax required by your language, the language ensures that the characteristics of the class and its members are stored (as metadata) along with the implementation of the class.

  • Interfaces

An interface is basically a class definition. It itself cannot be instantiated, rather it is implemented by other classes. Interfaces can be defined and implemented in VB6 albeit with some workarounds and limitations.

For example, in VB6 you cannot use one variable alone to access the methods of the interface and of the implementing class–you have to declare two variables, one as the interface and the other as the implementing class and point both of them to the same instance. VB.NET has a different and more straightforward implementation of interfaces.

Advertisements