We use cookies to distinguish you from other users and to provide you with a better experience on our websites. Close this message to accept cookies or find out how to manage your cookie settings.
To save content items to your account,
please confirm that you agree to abide by our usage policies.
If this is the first time you use this feature, you will be asked to authorise Cambridge Core to connect with your account.
Find out more about saving content to .
To save content items to your Kindle, first ensure [email protected]
is added to your Approved Personal Document E-mail List under your Personal Document Settings
on the Manage Your Content and Devices page of your Amazon account. Then enter the ‘name’ part
of your Kindle email address below.
Find out more about saving to your Kindle.
Note you can select to save to either the @free.kindle.com or @kindle.com variations.
‘@free.kindle.com’ emails are free but can only be saved to your device when it is connected to wi-fi.
‘@kindle.com’ emails can be delivered even when you are not connected to wi-fi, but note that service fees apply.
As you write more and more complex programs, you will find situations where you want to define classes that are so abstract that you will not want users to implement them directly. Instead, you will want to derive classes from these abstract classes that define more specific data and behavior. Abstract classes are implemented in VB.NET using the MustInherit keyword.
A simple example that beautifully illustrates the concept of abstract classes is food. When you go to a restaurant, you don't order just food. You order some type of food, such as steak, or a salad, or apple pie. Each of these is a specific instance of food, sharing some characteristics with the others, while obviously also differing from the others in substantial ways. Abstract classes let us define a high-level abstract object, such as food, that we can then use as a base class for many different derived classes. Because we would never want to instantiate the abstract class, we mark it abstract (MustInherit) so that it is clear the class is to be used as a base class only.
Creating Abstract Classes
To designate a class as an abstract class in VB.NET, we use the MustInherit keyword. Once a class is defined this way, we can only use the class as a base class for other derived classes.
Within an abstract class, we can declare the usual private data members, constructor methods, property methods, and so on.
One of the most confusing aspects of OOP is determining the proper access modifier to use for classes and class data members and methods. If you provide too much scope for a data member or method, you risk violating data encapsulation, leading to unwanted data access. If your scope is too restrictive, other classes that need access to a class's data or methods won't be able to access them. In this chapter we discuss the different access modifiers, how they are used to manage class member and method scoping, and when to use each modifier. At the end of the chapter we discuss how these access modifiers work with classes themselves.
The access modifiers available in VB.NET are the following:
Public
Private
Protected
Friend
Protected Friend
We also discuss the modifier Shadows in this chapter. A method declared as Shadows in a derived class hides any methods in the base class with the same name. In effect, a method that shadows another method redefines the shadowed method's behavior.
PUBLIC ACCESS
A class member or method marked as Public can be accessed by any part of the class body, by any part of the project in which the class definition is located, or from an assembly built from the project containing the class definition. This is the least restrictive access and is frequently misused by many programmers.
Reflection refers to the ability of a VB.NET program to access the metadata stored in both running and existing assemblies. Using these metadata, you can examine the contents of a program, manipulate the metadata in the assembly, and even dynamically create and execute objects at runtime. Reflection allows us to dynamically invoke class member functions and even instantiate class objects dynamically.
Attributes are custom-written metadata you can add to an existing assembly. Attributes are used for several purposes:
to indicate whether a class is serializable (see Chapter 13 for information on what this means);
to indicate individual class fields that are not serializable;
to perform conditional compilation; and
to create strongly named types.
Attributes are created as classes that inherit from the System.Attribute class. Attributes are accessed using reflection, so these two topics build on each other.
USING REFLECTION
As we've already stated, reflection allows us to examine the metadata found in our VB.NET programs. To use reflection, we have to import the System. Reflection class into our application. From there, we have to decide which assembly we want to inspect and which metadata we want to look at in the assembly.
Returning Metadata from an Assembly
Assembly metadata can be returned from assemblies that exist on a machine and assemblies that are currently running on a machine. An assembly's metadata are stored in the assembly's manifest, either in a PE (portable executable) file with the MSIL code for the assembly or in a standalone PE file.
This chapter presents an overview of the syntax and primary constructs of the Visual Basic.NET (VB.NET) language for programmers unfamiliar with VB.NET. This is not a tutorial chapter, however, so if you are new to programming you should study another text on VB.NET before continuing with this book. If, though, you are coming to VB.NET from some other language, such as C++ or Java or even Visual Basic 6, you should read through this chapter to familiarize yourself with the language.
NET PROGRAMS
There are two ways to build programs in VB.NET. One is to use the Visual Studio.NET Integrated Development Environment (IDE). The other is to use the command-line compiler packaged as part of the.NET Framework Software Development Kit (SDK). In this section we'll discuss developing programs with the command-line compiler, since this software is free and can run on any of the modern Windows operating sysems (Windows 98 and beyond).
VB.NET Program Types
With VB.NET, you can write many different kinds of programs. A VB.NET program that makes use of a graphical user interface (GUI) is a Windows application. A VB.NET program that uses the command-prompt console for input and output is called a Console application. You can also write Internet applications, Windows Services applications, and other types of applications.
A Windows application is by necessity written in an object-oriented manner. This chapter discusses the code generated by VS. NET when a Windows application is built. We'll examine both the code generated by VS. NET and the code created when a programmer builds an application. We will also examine how to use object-oriented principles in the code the programmer adds to the application.
As the noted computer scientist and education theorist Seymour Paper once stated, “You can't think about thinking without thinking about thinking about something.” Likewise, you can't examine building a Windows application without having a Windows application to build. To that end, the application we'll use to illustrate how object-oriented principles aid the creation of a Windows application is a basic calculator, similar to the one found in Windows. By picking a rather simple application that uses many widely employed Windows features (e.g., textboxes, buttons, and labels), we can focus on how taking an object-oriented approach makes the development easier and more efficient. We should also mention that this chapter is not designed to teach a novice how to create a Windows application; rather it teaches how to create a Windows application in an object-oriented way. We assume the reader already knows how to place controls on a form and already knows the basics of writing event-driven code.
Of all modern programming languages, Standard ML has ascribed perhaps the highest priority to rigorous semantic definition. It is therefore the preferred language for many applications where rigor is important; this is notably true of tools for formal program analysis. It has also gained users who value its high degree of portability, a direct consequence of the unambiguity of its definition.
Now Emden Gansner and John Reppy have equipped SML with another essential ingredient: a library of signatures, structures, and functors which will greatly ease the programmer's task. The SML Basis Library has been long in gestation, but this has ensured that it contains the right things. Only by close cooperation with users, over a considerable period of time, can one be sure of consistency and balance in defining a library. We can therefore be confident that the Basis Library will bring SML into still wider use, and we owe warm thanks to its creators for undertaking an arduous task with skill, care, and dedication.
One essential for the success of a general-purpose language is an accompanying standard library that is rich enough and efficient enough to support the basic, day-to-day tasks common to all programming. Libraries provide the vocabulary with which a language can be used to say something about something. Without a broad common vocabulary, a language community cannot prosper as it might.
This document presents a standard basis library for SML. It is a basis library in the sense that it concerns itself with the fundamentals: primitive types such as integers and floating-point numbers, operations requiring runtime system or compiler support, such as I/O and arrays; and ubiquitous utility types such as booleans and lists. The SML Basis Library purposefully does not cover higher-level types, such as collection types, or application-oriented APIs, such as regular expression matching. The primary reason for limiting the scope in this way is that the design space for these interfaces is large (e.g. choosing between functors and polymorphism as a parameterization mechanism) and, unlike the case with lists and arrays, we do not have many years of common practice to guide the design. It is also the case that the SML Basis Library specification is a substantial document and expanding its scope would make it unwieldy.
The primary purpose of this book is to serve as a reference manual for the Basis Library, describing as clearly and completely as possible the types, values, and modules making up the Library.