|
Constructors: When an object is created it is often nice to be
able to provide it with an initial set of data so it can initialize
properly. Until now we've had to create an object, then call a separate
method to initialize it. In VB 7 we'll have object constructors, allowing
us to pass values to an object as it is being createdno second
step required. This is one of my favorite features as it simplifies
coding and helps reduce errors when working with objects.
Encapsulation: The idea that we can create a set of procedures
(methods and properties) that form an interface. Other code can be written
to use these methods without knowledge of the code written within them.
This code is called an implementation. The implementation is encapsulated
within the interface.
Free-threaded: Threading is a complex concept. Free-threading
is basically the idea that our application can do more than one thing
at a time. For instance, we might be printing a document in the background
while the user continues to interact with our application. Free-threading
is very important when creating highly scalable server-side components,
and it is equally useful when creating very interactive user interfaces
(now we can easily implement a Cancel button to stop a long-running
task).
Inheritance: Often considered the key to being object-oriented,
this is the concept that an object can gain the interface and actual
behaviors (implementation) of another object and can then extend that
interface or those behaviors. I may create a generic Product object
that handles things common to all my products. From it, I may create
a NonTaxableProduct and a TaxableProduct. Both would inherit the original
Product object's interface and behaviors, but would extend or change
some of those behaviors as needed.
Initializers: Today in VB we first declare a variable, then
we give it a valuetwo separate lines of code. An initializer allows
us to both declare the variable and give it an initial value all at
the same time. While this is a subtle feature change, it leads to smaller,
simpler, more maintainable code.
Object-based: It is relatively easy for a language to be object-based.
Though the criteria are ill-defined, object-based basically describes
a language that can easily and directly interact with objects. Visual
Basic has done this since version 3 through the DAO objects, controls,
and then later many other objects such as ActiveX controls, RDO, ADO
and so on.
Object-oriented: To be object-oriented, a language must meet
three criteria. It must support encapsulation (which VB has done since
version 4). It must support inheritance (which VB 7 will support) and
it must support polymorphism (which VB has done since version 4surprised?
Read the section on polymorphism below). So in version 7, VB will be
fully object-oriented, as it will meet these criteria.
Overloading: Objects often perform the same function on similar
types of data. For instance, we may need to be able to add both Service
and Product line items to an Order object. To date, we've had to implement
an AddService and an AddProduct method to the Order object to make this
happen. With overloading we can implement an Add method for each case
and allow VB to automatically call the correct one as our program runs.
Overriding: When using inheritance, our new class gets all the
methods from the parent class. However, we may want a different implementation
for one of those methods. This is done by overriding the original (inherited)
method with our own code. Typically our new code can also call back
into the parent object's original implementationbased on the VB
7.
Polymorphism: Simply put, this is the ability to have two different
objects, of two different types, that both implement the same method.
This allows us to write code that calls that method regardless of which
type of object is in use at the moment. VB has supported this through
late-binding since version 4, and through the Implements keyword and
multiple COM interfaces since version 5. Now, in version 7 we'll add
the ability to use polymorphism with inherited interfaces as well. In
the end, VB 7 will have an incredible amount of flexibility when implementing
polymorphism.
Shared Members: Otherwise known as class or static members,
these are methods or variables that are equally available to all instances
of a class. Every object created, based on a given class, shares these
same variables and routines. This means, for instance, that we can easily
write a routine that counts how many instances of a class exist at any
point in time by keeping a simple shared counter variable.
Structured Exception Handling: Replacing the venerable, and
often inflexible, On Error Goto statements, we have a new structure
for handling errors. This is a block structure consisting of the Try,
Catch, and Finally keywords. Code in the block between Try and Catch
is protected in such a way that if an error occurs, a Catch block will
run. After any Catch block is run, the code in the Finally block will
run, allowing us to clean up after an error.
Type Safety: Visual Basic today is very aggressive about converting
variables of one type to another. It automatically converts numbers
to text for printing, and much more. Sometimes this can lead to unexpected
side effects in our code. With type safety, we will have the option
to force VB to avoid many automatic type conversions. While this means
we programmers will have to do our own type conversions, type safety
can be very beneficial when trying to avoid unexpected side effects.
User Interface Inheritance: Language inheritance isn't enough; VB 7
will also include inheritance for VB forms. This means we can create
a basic form template, perhaps with a standard toolbar, corporate logo
and colors, and then derive all of our other forms from this first form.
All the other forms will inherit the look and code from the original.
A change to the original form (say a new corporate logo) will automatically
ripple out to all the other forms with a simple recompile. Wow!
WebForms: For many years VB has been widely regarded as having
an incredibly powerful forms designer. We've also enjoyed the ability
to double-click on a control to have the code window pop up, so we can
write code for that control's events. WebForms bring this technology
to HTML development. WebForms are browser-neutralall the code
runs on the Web serverbut at the same time they provide us with
drag-and-drop form design and the ability to double-click a control
to bring up a code window where we can write server-side code. Better
still, this code is real Visual Basic, not merely VBscript!
Web Services: A Web service is a component that runs on a Web
server and allows client programs to call its methods over HTTP. Each
method on the component appears as a URL and may return data (perhaps
an XML document) and accept parameters. This technology is based on
the open SOAP specification, so now our server-side components can be
available to virtually any client, regardless of language or platform.
Now that we have a good understanding of the terms and concepts around
the new features announced for VB 7, the remaining questions are: How
does Microsoft plan to implement each of these new features, and more
importantly, how can we fully exploit them to become more productive
and to build more-powerful applications?
One thing is for certainwith these changes, VB will become a
fully object-oriented language. Coupled with free-threading and the
other innovations announced, VB is likely to remain the most widely-used
development tool in the world.
|