Tải bản đầy đủ (.pdf) (32 trang)

Tài liệu Module 8: Solution Design and the Component Object Model ppt

Bạn đang xem bản rút gọn của tài liệu. Xem và tải ngay bản đầy đủ của tài liệu tại đây (315.09 KB, 32 trang )

Module 8: Solution Design and the
Component Object Model


246

Module 8: Solution Design and the Component Object Model

Module Overview

Module 12: Introduction to
Functional Specifications
Module 11: Designing the
Presentation Layer

Module 1: Course Overview

Module 10: Completing the
Physical Design

Designing Business
Solutions

Module 9: Designing Solutions with
Microsoft Technologies
Module 8: Solution Design and the
Component Object Model

Module 2: Solution Design Using
the MSF
Module 3: A Services-based


Approach to Solution Design
Module 4: Business Solution
Conceptual Design

Module 7: Selecting Solution
Technologies

Module 5: Business Solution
Logical Design

Component Object
Model Basics

Module 6: Beginning Physical
Design

Activity 8.1: Simulating COM
Communication

Review

Module 8: Solution
Design and the
Component Object
Model

Application
Development and COM

Distributed Component

Object Model Basics
COM-Based
Design
Activity 8.2: Identifying the Impact of
Distributing COM Components


Module 8: Solution Design and the Component Object Model

247

! Overview
Slide Objective

To provide an overview of
the module topics and
objectives.

"

Component Object Model Basics

Lead-in

"

Activity 8.1: Simulating Component Communication

"


Application Development and COM

"

Distributed Component Object Model Basics

"

Activity 8.2: Identifying the Impact of
Distributing COM Components

"

COM-Based Design

"

Review

In this module, you will learn
about COM, DCOM, and the
benefits of COM design.

In this module...
In this module...

Microsoft’s Component Object Model (COM), Distributed Component Object
Model (DCOM), and COM+ each provide services and structure that aid in
implementing large applications. It is important to understand these models
because they will help you make good decisions about selecting the candidate

technologies for developing the business solution. These models also provide
many benefits that can be used by the application designer and developer. This
module describes these technologies and presents guidelines for implementing
them.
After completing this module, you will be able to:
"

Describe the Microsoft® COM standard.

"

Describe COM classes, components, objects, and interfaces.

"

Explain the relationship between COM and application development.

"

Describe DCOM and its relationship to COM.

"

List the benefits of using COM in a solution design.


248

Module 8: Solution Design and the Component Object Model


! Component Object Model Basics
Slide Objective

To explain the purpose of
the section and what
students will learn in the
section.

"

COM Standard

"

COM Components

"

COM Interface Basics

"

COM Classes

"

COM Objects

In this section...
In this section...


COM is a foundation for successful application designs based on Microsoft
technologies.
In this section, you will learn about COM and how it enables applications to
easily communicate and interoperate. At the end of the section, you will
practice what you have learned in an activity that simulates COM and
application interaction.


Module 8: Solution Design and the Component Object Model

249

COM Standard
Slide Objective

To define COM and
introduce the COM
standard.

"

Binary standard for object interaction

"

Part specification

"


Part implementation

COM, as a binary standard for object interaction and addresses many
component challenges. It is a binary standard because it is in part specificationoriented and in part implementation-oriented.
"

COM is specification-based in that it defines objects by using a language in
a location-independent manner. In addition, it defines how to locate and
identify components, as well as instantiated objects.

"

COM is also implementation-based in that it provides system services that
know how to locate components, load them into memory, execute their
methods, and access their properties. Additionally, COM can perform
interprocess and remote communications.

"

COM defines the exact binary representation of an interface. As a result,
any programming language or tool that supports COM must create object
interfaces that strictly correspond to this standard binary representation.


250

Module 8: Solution Design and the Component Object Model

COM Components
Slide Objective


To introduce COM
component information.

"

Three basic packaging methods:
$
$

Executable

$

"

Windows NT services
Dynamic-link library

Multiple physical locations:
$
$

Delivery Tip

Although components are
sometimes called servers,
we avoid confusion with
server computers by
maintaining the original

term, “component,”
throughout this module.

Delivery Tip

For the remainder of this
section relating to COM, we
will focus on components
implemented as DLLs
because these components
are most prevalent in n-tier
applications.

Local components

$

"

In-process
Remote components

Binary files used to instantiate COM objects

There are three packaging methods for COM components: a Microsoft
Windows® service, an executable file, or a dynamic-linked library (DLL).
Windows services are simply applications that are required to always be
running. Windows executable files are often used if an application must provide
a user interface in addition to furnishing COM objects. In most development
scenarios, components are packaged as DLLs.

Additionally, components are described by their location relative to their calling
application, which is referred to as a client or consumer. In-process components
are implemented as DLLs and execute within the same process as the client.
Local components are often executable files or a Windows service. They are
executed on the same computer as the client, but in a separate process. Remote
components can be packaged as required, as well as located and executed on a
separate computer from the calling client.
A COM component is a binary unit of compiled application code that can be
used to instantiate COM objects into the memory of a computer. For a given
COM class identifier — also called a unique class identifier (CLSID) — a
component will include the COM class, the code to instantiate and execute a
class object, and usually the code required to create installation entries into a
system’s registry.


Module 8: Solution Design and the Component Object Model

251

COM Interface Basics
Slide Objective

To describe a COM
interface.
"

Interface Description Language

"


COM interfaces provide the
means for accessing COM
components.

Interface contracts

"

Lead-in

Available COM interfaces
$

IUnknown

$

IClassFactory

$

IDispatch

A COM interface is a contract between a provider of services, the COM class,
and the consumer of those services (the client). The interface is the only means
of communication between the provider and consumer. It defines how messages
and information will be accepted by the component, as well as how information
will be returned to the client.
Interface Description Language (IDL) is a language similar in structure to C++,
which describes the exact syntax of an interface. Interface definitions begin

with an interface keyword; interface attributes are contained in square brackets
preceding the interface keyword.
To be defined as a COM interface, an interface must satisfy the following
requirements:
"
"

According to the COM
specification, GUIDs can be
generated at the rate of
10,000,000 per second per
computer for the next 3,240
years without risk of
duplication.

The interface must ultimately derive from the special interface IUnknown.

"

Delivery Tip

A unique identifier must identify the interface.
Once published, the interface must be immutable. In other words, the
interface cannot be changed.

Instead of using string identifiers alone to identify COM interfaces, COM
implements globally unique identifiers (GUIDs). GUIDs are 128-bit, systemgenerated integers that uniquely identify components. The algorithm used to
generate GUIDs is statistically guaranteed to generate unique identification
numbers.
The IUnknown interface defines the fundamental behavior for COM interfaces.

Clients can rely on this behavior because all COM interfaces derive from
IUnknown. The IUnknown interface helps resolve the technical challenge of
providing a standard means to interact with objects. It also provides three
important features of interaction: interface navigation, interface versioning, and
object lifetime management.


252

Module 8: Solution Design and the Component Object Model

IClassFactory is a standard interface for communicating with class objects. As
a result, clients need only one mechanism to create any type of COM object.
The most important method of IClassFactory is CreateInstance, which creates
an object and returns a specified interface pointer to the object.
IDispatch is the standard COM interface that provides automation and
programmatic access to an object. By implementing IDispatch, components
can expose any number of functions to clients. Clients access all functionality
through a single well-known function.
Developers using certain development tools, such as Microsoft Visual Basic®,
are shielded from the complexity of defining interfaces using IDL. Their
compilers manage the creation, assignment, and registration of the interfaces.


Module 8: Solution Design and the Component Object Model

253

COM Classes
Slide Objective


To introduce COM classes.

Lead-in

A COM class is simply an
instance of a named COM
interface.

"

Name and define a public interface

"

Provide
$

A means to instantiate objects

$

Separation of the interface from the implementation

A COM class defines the public interface that may be accessed by a client and
defines how to access the interface from a client. A COM class is also given a
CLSID and a string identifier called a programmatic id (ProgID). Every COM
class has an associated class object (also known as a class factory) that provides
the ability to create instances of a specific COM class. These instances of a
COM class differ from most language-based classes in that after an instance has

been created, its specific class is no longer relevant to the client. All interaction
with this instantiated object occurs through interface pointers. These pointers do
not allow access to the implementation classes used to instantiate the object or
to the internal code that allows the object to perform work.
The rigorous separation of interface and implementation is a key feature of
COM. This “black box” concept greatly simplifies the client coding effort
because the client does not need to know how the components work, only that
they do work.


254

Module 8: Solution Design and the Component Object Model

COM Objects
Slide Objective

To describe a COM object.

Lead-in

"

Are run-time instances of a COM class

"

Simplify access to application logic and information

"


Are accessible by multiple clients

"

Provide a means for life-cycle management

"

A COM object is a run-time
instance of a COM class.

Reduce client application code

As with most object-oriented models, COM objects are run-time instances of a
particular COM class. These objects live in memory and are executed by a
computer microprocessor.
When COM objects are instantiated, their underlying code and actual class
structure are hidden from the client. Because the application logic and
information structure are hidden, the client is provided with a significantly
simplified interface and the ability to perform complex application logic, as
well as given access to complex information structures. This simplification also
reduces the amount of code required by the client application.
Many clients can use an instantiated object simultaneously, and a single client
can use the same instantiated object multiple times. Only a pointer is given to
the client or clients to provide access to the instantiated object.
Delivery Tip

Technically, the client
receives a pointer to a

pointer to a v-table of
pointers when using
IClassFactory. When using
IDispatch, the client must
query the interface each
time to get the information.

As mentioned, a single client may need to use multiple occurrences of the same
object at the same time. For efficiency, a duplicate copy of the object’s
executable code is typically not created in memory. As pointers are given to the
client, the object increments and decrements a reference counter through the
IUnknown interface each time a new instance of the same object is required.
COM’s life-cycle management of the object allows for more efficient use of
computer resources and provides COM with a mechanism for knowing when an
object is no longer being used (that is, when its reference count is zero).


Module 8: Solution Design and the Component Object Model

255

Activity 8.1: Simulating Component Communication
Slide Objective

To introduce the activity.

This activity will demonstrate the specific way in which COM components
communicate with one another.
In this activity, you will simulate a COM component communicating with other
COM components.

After completing this lab, you will be able to:
"

Demonstrate how COM technologies enable component-based solutions to
function.


256

Module 8: Solution Design and the Component Object Model

! Application Development and COM
Slide Objective

To explain the purpose of
the section and what
students will learn in the
section.

"

COM and Windows DNA

"

Calling COM Components

"

COM Threading Model


"

COM and Marshalling

In this section...
In this section...

In this section, you will learn about the application development issues
surrounding COM specification. You will learn how to use COM components
and how a COM component’s internal code can function.


Module 8: Solution Design and the Component Object Model

257

COM and Windows DNA
Slide Objective

To explain how COM relates
to Windows DNA.
"

Foundation for layer independence

"

Public interface with standard behaviors


"

Client language independence

"

Creation language independence

By definition, Windows Distributed interNet Applications (Windows DNA)
uses COM as the foundation for interapplication and intraapplication
communication. Because Windows DNA architecture recommends a
cooperating, multiple-layer architecture, COM provides the communication
mechanism between the presentation, business, and data layers.
COM components publish a public interface that may be accessed by any
service layer. COM also provides the standard communication mechanism for
applications requiring access to additional system services, such as Microsoft
Transaction Services, within the Windows DNA business service layer.
The nature of COM’s public interface and the fact that COM provides a “blackbox” execution standard (meaning that how the component executes is not
revealed or accessible from the client) allow the use of any development tool or
language to execute a COM component. Consequently, the appropriate
development tool can be chosen for each service layer.
Finally, COM provides a standard way for the operating system to publish a
component’s public interface and process components. As a result, as long as a
development tool supports the creation of COM components, any tools can be
used to code COM components. This choice of independent component coding
also allows the development team to use different tools to create components
for each service layer.


258


Module 8: Solution Design and the Component Object Model

Calling COM Components
Slide Objective

To explain the steps
required to call a COM
component.

"

Reference the component

"

Instantiate an object

"

Call the object’s interfaces

"

Destroy the object

To use a COM component, the component must first be referenced. How
reference is accomplished depends on the development environment, but it is
generally as simple as a menu choice or a declaration of a variable. Typically,
the ProgID is used to assign the component a variable name within the

application.
After the component is referenced, an object may be instantiated, incrementing
its reference count. This instantiation provides the client with access to the
object’s public interfaces. The client knows these interfaces through IDispatch
or IClassFactory.
When the object is instantiated, its properties can be set, its methods can be
activated, or events can be raised directly from the client.
An object should be released after it has served its purpose. The release process
decrements the object’s reference count and recycles the object pointers,
thereby freeing the memory that the client required. When the released object’s
reference count indicates that no additional objects are being accessed, the
memory associated with the object is returned by COM to the operating system.
Not releasing objects properly is a common problem and often noted as
“memory leaks.”


Module 8: Solution Design and the Component Object Model

259

COM Threading Model
Slide Objective

To explain the impact of a
threading model and the
threading models that COM
provides.

"


Application threading

"

Choices for threading
$

Single-threaded

$

Multithreaded

$

Apartment-model threading

Threading refers to the order in which operations can be performed by a
specific process. A process with multiple threads can appear to be executing
several things at once. However, this simultaneous execution actually occurs
only on computers with multiple processors.
COM components can be single-threaded, meaning that all instructions required
to perform its work can only be executed in sequence. Each execution “step” of
the component must wait for the previous “step” to complete. Think of it as a
single-file line going through a single door to enter a building.
In a multithreaded application, a single process may execute several tasks
simultaneously. As a result, a specific thread is not required to complete before
another task may be started. Continuing our example, think of this application
as multiple buildings with multiple doors with multiple people entering the
buildings at the same time.

Apartment-model threading is a method of multithreading that isolates the
threads and provides speed boosts over a single-threaded component. In
addition, it does not require as much internal plumbing as other forms of
multithreaded components to create thread-safe code. Using our example, think
of this method as specific, single-file lines entering multiple doors of a single
building.


260

Module 8: Solution Design and the Component Object Model

COM and Marshalling
Slide Objective

To explain the concept of
marshalling.

Lead-in

Marshalling allows different
kinds of processes to
communicate.

"

Marshalling enables communication

"


Marshalling is overhead

"

Marshalling occurs often

Marshalling refers to the packaging of information into a specific bundle by
using a standard format so that the information can be accessed by using a
dissimilar process.
When marshalling must occur to allow communication, there is overhead for
the calling process. Processing overhead is created by the calling process as it
bundles information into a standard format. Additionally, overhead is created
by the providing process as it unbundles information and places it into its
internal format. The amount of overhead required depends on the calling and
providing processes; however, certain types of marshalling can be costly in
processing resources.
Marshalling occurs often because dissimilar systems frequently must
communicate. Marshalling can occur between components executing in
different threading models. It can also occur when a client must access code
running in another process. Marshalling also enables DCOM communication
and Microsoft Transaction Server (MTS)-based components to communicate
across MTS packages.


Module 8: Solution Design and the Component Object Model

! Distributed Component Object Model Basics
Slide Objective

To explain the purpose of

the section and what
students will learn in the
section.

"

DCOM Standard

"

DCOM Component Location

"

DCOM Component Use

In this section, you will learn about DCOM. In particular, you will learn how
DCOM improves upon COM’s locational independence, thereby allowing
additional flexibility in packaging and deploying an application.

261


262

Module 8: Solution Design and the Component Object Model

DCOM Standard
Slide Objective


To explain the DCOM
standard.

Lead-in

DCOM is a specification that
enables COM components
to reside on different
computers on a network and
be called remotely.

"

DCOM components are computer-independent COM
components

"

Remote computers must be located

"

Component use appears seamless

Technically, DCOM is simply the protocol (that is, the language and structure)
that components use to communicate over a network. Most references to
DCOM use the concept of separating a COM component onto different
computers. Consequently, we will refer to DCOM as the interface specification
and communication protocol that allows COM components to reside on
different computers and execute remotely.

Because part of a DCOM component is on a remote computer, the remote
computer must be properly located and a communication session must be
established. Successfully locating and communicating with the remote
computer is dependent on network availability.
DCOM also allows components to appear to the client as executing on the local
client computer. This DCOM characteristic means that a developer trying to
locate and execute COM and DCOM components does not have to implement
application code differently for each.


Module 8: Solution Design and the Component Object Model

263

DCOM Component Location
Slide Objective

To explain the issues
involved in locating DCOM
components across a
network.

Lead-in

Separating components
across different computers
on a network introduces a
new set of issues to be
addressed.


"

Accessing named computers

"

DCOM over networks

"

DCOM over HTTP

DCOM components are referred to on the local computer by the remote
computer’s name. To establish a DCOM session, this name must be resolved to
a lower-level network name such as an Internet Protocol (IP) address.
DCOM components can reside and execute anywhere on a network. Because
execution and control occur across a network, the interfacing of DCOM
components is susceptible to all of the common problems of a network,
including overloaded bandwidth, unresolved computer names, network
protocols, firewalls, and proxies. The speed of communication can become a
bottleneck for low-bandwidth connections. The speed of large quantities of data
traveling between the client and object can also be affected by network
performance. Security is especially important in a distributed solution because
validating an accessing client may be necessary before access to an object can
be granted.
Because many remote clients will need to gain access to components through
the Internet, DCOM enables the use of COM components over HTTP. Using
DCOM over HTTP can assist developers who are using distributed components
by enabling communication through network security devices, such as firewalls
that block certain types of network traffic.



264

Module 8: Solution Design and the Component Object Model

DCOM Component Use
Slide Objective

To explain the issues
involved in executing DCOM
components.

Lead-in

When using DCOM
components, local clients
are shielded from the
distributed nature of DCOM.

"

DCOM components appears as local COM components

"

DCOM remote network access is transparent

The DCOM component is physically separated on different computers. The
local client computer accesses the DCOM component through a local COM

stub/proxy. As a result, the local computer thinks that the component is
executing as an in-process COM component. Technically, the local, in-process
component communicates with the remote component and does not actually do
the work.
For a developer, calling a DCOM component and a COM component requires
using identical instantiation syntax. Remember that a local stub/proxy
component must be installed on the local computer for the local computer to be
able to access the remote portion of the DCOM component.
Network access by the DCOM object is transparent to the calling client. This
network access is handled by the low-level plumbing of the COM and DCOM
engines. Networking issues may arise as objects await results. For example,
multithreaded applications may need to be enhanced to handle the potential
delay of accessing components across a network.


Module 8: Solution Design and the Component Object Model

265

Activity 8.2: Identifying the Impact of Distributing COM
Components
Slide Objective

To introduce the activity.

In this activity, you will identify potential problems in a distributed component
topology.
After completing this lab, you will be able to:
"


Identify issues in a distributed component topology.


266

Module 8: Solution Design and the Component Object Model

! COM-Based Design
Slide Objective

To explain the purpose of
the section and what
students will learn in the
section.

Lead-in

In this section, you will learn
about some of the benefits
of COM and DCOM
designs, the future of COM,
and some guidelines related
to implementing COM
applications.

"

Benefits of COM Design

"


Benefits of DCOM Design

"

Future of COM: COM+

"

Windows 2000 COM+ Support and Services

In this section, you will learn about how implementing n-tier applications by
using COM and DCOM simplifies and enhances application development.
Additionally, new versions of the COM specification, collectively known as
COM+, provide new features and new challenges to implementing COM-based
applications.


Module 8: Solution Design and the Component Object Model

267

Benefits of COM Design
Slide Objective

To explain some of the
benefits of COM design.
"

Technology to enable developers to assemble

applications from prebuilt parts

"

Technical challenges that COM addresses
$

Component location and execution

$

Standards for component and application interaction

$

Maintaining language independence

A fundamental goal of COM is to enable developers to create applications
assembled from prebuilt parts or components. For example, an order-entry
application could use a data-entry grid component to simplify entering ordered
items into the application.
To make this goal a reality, several technical challenges must be met:
"

The first challenge is to locate the component on a computer or network,
and once located, to execute the component. Applications must also be
available to identify and execute vendor-created components.

"


The next challenge is to provide standards for the interaction between the
application and the components. If no standards exist, the overhead cost of
learning how to use such objects creates a barrier to reusing code. Ideally, a
standard mechanism for object interaction would not distinguish the location
of any given object, whether the object exists within its own application’s
process, within another process on the application’s host computer, or
within a different process on another computer altogether.

"

The final challenge is to take advantage of true language independence. This
challenge is complex for any object model. Every element involved in a
particular object — memory allocation, method names, parameter types,
calling conventions, and so on — must be defined in such a way that an
object can be created in one programming language and used by another.
Application developers should not need to spend valuable time or energy
worrying what programming languages or tools are used to create a desired
component. Without wide support from development languages and tools,
many different models will fragment the component market. This
fragmentation raises the costs of identifying, purchasing, and developing
components that are operable only in certain environments.


268

Module 8: Solution Design and the Component Object Model

Benefits of DCOM Design
Slide Objective


To explain some of the
benefits of a DCOM design.

Lead-in

There are many benefits to
designing a DCOM-based
application.

"

Improves scaleable architectures

"

Does not require a change to the code base

"

Controls remote surrogate processes

DCOM components allow for scalability beyond the basic “buy a bigger
machine” scaling option available with standard COM components.
Components can be executed on computers specifically tuned to provide these
remote component services, and clients do not incur the memory and processing
overhead associated with the actual component execution.
Because DCOM is implemented at the lowest operating system levels, it is
transparent to component developers and requires no additional functionality or
application code to be built into the objects.
DCOM also provides an advantage to developers who need to remotely control

the execution of application logic. DCOM inherently provides all of the control,
communication, monitoring, error handling, and execution of remote
components. Developers are no longer responsible for building all of the
application code for their application’s remote execution of components.


Module 8: Solution Design and the Component Object Model

269

Future of COM: COM+
Slide Objective

To explain the future of
COM, COM+.

Lead-in

COM+ is the next
generation of the COM
specification.

"

Easier implementation

"

Integrated support for:
$

$

Inheritance

$

Dynamic load balancing

$

"

Transactions

Integrated security

Tighter integration with system services

COM+ will further ease implementation for component developers while also
allowing a number of new features to be used natively, without the need for
consuming customized code.
COM+ contains support for many new features. These features include
automatic synchronous and asynchronous transaction support, inheritance, load
balancing across computers, and integrated security (including integration with
Active Directory™).
In addition to integrating MTS, additional system services have also been
integrated with COM, such as Microsoft Message Queue (MSMQ) Services.
The name given to this unified set of component services is COM+ Services.
This integration of COM and system services allows applications written to use
COM+ to automatically take advantage of these services. The different client

calling mechanisms of COM, MTS, and MSMQ have been combined into a
single COM+ mechanism.


×