1
Starting Out With Components
As our customers, our managers and the sales team ask for
increasingly complex applications, the demands made of software developers are
growing at an ever-increasing rate. Lately, the vogue for companies, quite
rightly, has been to automate their business processes. Now the drive is to
integrate all of these disparate systems together, often with the addition of a
web interface so that access to these products and services is more widely
available.
The continual growth in the adoption and expansion of
computer-based systems leads to more sophisticated (or complicated)
applications—some of which take years to develop, or evolve without direction
into unmanageable systems that no single developer fully understands. When the
system requires maintenance or an upgrade, where's the developer who built the
thing in the first place? They're either 'too busy', or they've moved on to
richer pastures (not uncommon in today's market). That means that some other
poor developer has to bear the pain and hardship of working out where changes
need to be made—and the ramifications that these changes will have on other
parts of the system.
Concerns over scalability, structure and maintenance of
these increasingly complex systems, coupled with the demands that are the very
nature of software development, mean that something is needed to ease the
burden. Components have got a lot
to offer us. If you think of a component as a small, self-contained nugget of
code that we write to sit at a well-defined point in a system's architecture
and perform certain (related) tasks, we can begin a list of the benefits of
components right here:
q
Because by itself it is a lot simpler than the entire
application, we can maintain it easily.
q
Because it's self-contained, we can upgrade simply by
taking out the old component and putting the new one in its place. The same
applies to components that we discover to contain bugs.
q
If it's useful elsewhere, we can reuse it—we may borrow
it for our own purposes, or put it on the market.
We could go on, but we'll save that for later. The point is
this: everything we've said so far is just as applicable to ASP and web
development as it is to any other kind of development. Web sites are becoming
more complicated: our ASP applications are being asked to incorporate the
functionality of traditional applications; to centralize the point of access
for end users who need to get at different applications; to handle increasing
numbers of users. The fact is, we need to give components some serious
consideration.
Components are already an important part of programming and
software development, and the ability to build and use components is a valuable
tool in any programmer's arsenal. In fact, these days, component building is
arguably an essential skill.
In this chapter, we're going to convince you that you
already know quite a bit about programming with components; we'll look at some
typical scenarios in which components are used; and we'll begin to investigate
the impact that component programming has on application design. By the end of
the chapter, you should understand that componentization isn't just about code reuse—it implies a new
way of creating applications, opening the door to techniques and technologies
that aren't available in 'traditional' programming. Specifically we will see:
q
The advantages of using components
q
The basics of COM—Microsoft's Component Object Model
q
An introduction to 3-tier and n-tier application development
q
Examples of situations where you're probably using components
already
q
How to build and use our first component
The Advantages of Componentization
Consider the question, "What's the best approach to the
solution of a complex problem?" Perhaps the most obvious answer is this:
q
Break it up into a number of smaller parts, each of
which is self-contained and can be easily understood
q
Solve each of the smaller parts (or use a ready-written
solution—you might have a solution lying round from a previous project, or you
might buy in a third-party solution)
q
Bring each of the smaller parts together to create the
overall solution
This approach generally works very well—and programming is
no exception. The reason is probably its simplicity—but this simplicity is the
key to good software engineering and development.
COM—the Component Object Model
The good news is that there is an established technology
available to us today that allows us to build our applications this way. It is
called COM—the