The Microsoft Way COM - Component Object Model

advertisement
COM - Component Object Model
The Microsoft Way
Original slides
Jens Gustavsson
Updated / extended (2007)
Mikhail Chalabine
Binary standard
Fundamental entities: Interface, Component
One component can implement any number
of interfaces
COM technologies
–
–
–
COM+
Distributed COM (DCOM)
ActiveX® Controls
1
A COM component
Client variable
2
A COM component
Interface node
function 1
function 2
function 3
function 4
function 5
Client variable
Interface node
Client variable
Interface node
function 1
function 2
function 3
function 4
function 5
function 6
function 7
function 8
Component
Component
3
4
Two Questions
QueryInterface
How does a client learn about which
interfaces a component implements?
How does a client compare the identity of
COM objects?
Client variable
Interface node
Client variable
Interface node
QueryInterface
function 2
function 3
function 4
function 5
QueryInterface
function 7
function 8
Component
5
How to draw them
6
Reference Counting
IUnknown
All interfaces contain:
–
–
IPersistStorage
Properties
–
–
IViewer
–
–
ISecure
Cycles
Simple
Fast (objects removed as soon as count is 0)
Expensive (too many operations)
Tracing Garbage Collection in .NET instead
–
7
AddRef
Release
Determine reachable objects (transitive)
8
COM object reuse
Containment
No inheritance between components
Two alternative solutions:
–
–
IUnknown
IUnknown
Containment
Aggregation
IStream
IStream
IPrint
9
Containment
10
Aggregation
IUnknown
IStream
IUnknown
Outer exposes inner objects' interfaces
Inner object cooperation needed
Reference counting complicated
http://msdn2.microsoft.com/en-us/library/ms686558.aspx
IPrint
IStream
11
12
Polymorphism
Component Categories
Type of an object is the set of interfaces it
supports
A subtype is a superset of interfaces
IStream
IPrint
IStream
Logical grouping by functionality
A set of interfaces identified by GUID (CATID)
Windows system register stores info about
COM system
Interfaces as contracts (is a mess)
Predefined categories
Custom categories allowed
IViewer
IPrint
http://edndoc.esri.com/arcobjects/9.0/ExtendingArcObjects/Ch02/ComponentCategories.htm
ISecure
13
14
Interface versions
How to create a COM object
Published interfaces must never change
The GUID represents a specific version
Interface ID not enough
Procedural library for requesting objects
based on COM class
–
15
CoCreateInstance(Class id, Interface id)
System registry
16
COM Servers
Persistence
Contains a set of COM classes
A Factory for each class
Kinds of COM servers:
–
–
–
In-process (dll)
Local (exe)
Remote
CoCreateInstance does not initialize object
Structured storage
Monikers
–
Refer to objects by logical access path
17
18
DCOM - Distributed COM
OLE
Stubs and proxies (skeletons)
Datatype conversion by using NDR (Network
Data Representation)
Object Linking and Embedding
Based on COM
Application centered paradigm vs.
Document centered paradigm
Concepts:
Master
–
–
19
Document servers
Document containers
In place editing
Embed / link
Document
Referenced
Document
Reference
20
Controls
.NET
VBX
OCX (OLE Control)
ActiveX
Architecture similar to Java
Source
code
Compiler
Byte code
Class
library
Virtual
Machine
21
22
.NET
CTS - Common Type System
Architecture similar to Java
Source
code
Compiler
MSIL
System.Object - root of type hierarchy
Single inheritance
Multiple interface implementation
Access control
–
–
Class
library
Location: class, assembly, universe
Related by class inheritance or not
CLR
23
24
C#
Assemblies
Exemplary .NET language
Similar to Java
–
–
–
–
–
–
–
–
No inner classes, delegates instead
Properties
Struct
No checked exceptions
Metadata
Enum
Goto
Operator overloading
Deployment format
A set of files in a directory hierarchy
–
–
Must contain manifest (assembly metadata)
Can be tagged with culture label
–
module files
resource files
Satellite assemblies
Private / Shared
25
26
Strong names
GAC - Global Assembly Cache
Unique identification of Assemblies
Unique names (no one else has the same):
–
–
–
–
Assembly DB in Windows XP
Assembly retrieval controlled by policies:
–
publisher token
assembly name
version (major, minor, build, patch)
culture
–
–
Publisher policy
Application policy
Machine policy
Installer-GAC cooperation
Digitally signed based on whole assembly
Strong ID on assembly. Contents addressed
relatively
27
28
Version management
COM interoperation
The Common Type System anchors all
names in the names of the containing
assembly
Between managed and unmanaged code
COM callable wrappers
Runtime callable wrappers
http://msdn2.microsoft.com/en-us/library/ms973872.aspx
http://msdn2.microsoft.com/en-us/netframework/aa497266.aspx
29
30
Windows Form Components
Enterprise services
Similar to JavaBeans
System.ComponentModel.IComponent
Properties, events and delegates support
connection-oriented programming
Metadata to attach design time information
and behavior
Container
Services
–
–
–
–
–
–
Object pooling
Jut-in-time activation
Queued Invocation
Transactions
Resource management
Access control
[ES.Transaction(ES.TransactionOption.Required)]
[ES.JustInTimeActivation(true)]
31
32
The Microsoft Way
Original slides
Jens Gustavsson
Updated / extended (2007)
Mikhail Chalabine
33
Download