Advanced Interactive Programming Componentbased Programming - PowerPoint PPT Presentation

1 / 60
About This Presentation
Title:

Advanced Interactive Programming Componentbased Programming

Description:

The need for software reuse. Speed up software development process. Reduce software ... Requirements URD. System specification - SRD. System Design - ADD ... – PowerPoint PPT presentation

Number of Views:63
Avg rating:3.0/5.0
Slides: 61
Provided by: ChrisN83
Category:

less

Transcript and Presenter's Notes

Title: Advanced Interactive Programming Componentbased Programming


1
Advanced Interactive ProgrammingComponent-based
Programming
2
Outline
  • Component based programming
  • Motivation
  • Rationale
  • ActiveX technologies
  • COM/DCOM
  • ActiveX components
  • Create ActiveX controls in VB

3
Motivation
  • The need for software reuse
  • Speed up software development process
  • Reduce software development cost
  • Adapt to software (e.g. operating system) and
    hardware (e.g. microprocessor) changes
  • The observation
  • Many things in real world such as cars,
    computers, etc. are assembled from standard parts
  • Similar development circumstances recur
    frequently in the development of computing systems

4
Reuse and Reuse Levels
  • Reuse is a very broad term covering the general
    concept of a reusable asset.
  • Reuse could happen at different steps of software
    engineering
  • Requirements URD
  • System specification - SRD
  • System Design - ADD
  • Reuse could happen at different levels of system
    abstraction
  • Software source code - copypaste or OOP
  • Software binary code

5
Understanding Component
  • An executable binary piece of code, which has the
    following features
  • Non-context-specific, i.e., functionally
    self-contained and independent of any specific
    environment or applications
  • Composable with other components, i.e., used as a
    unit of third party composition, thus support
    multiple use
  • A unit of independent deployment and versioning
  • Encapsulated, i.e., a component needs to
    encapsulate its implementation and interact with
    its environment through well-defined interfaces

6
Component-based Programming
  • Component-based programming is also known as
    component software development, which refers to
  • Buy components from third parties
  • Develop own components
  • From scratch use what you learn such as OOP
  • Or composition of other components
  • Or a combination of the above two approaches
  • Reusing and assembling components into
    applications
  • Systems composed of software components are
    called component-based software or componentware

7
Object oriented programming Vs. Component-based
Programming
  • Reuse of source code via object-oriented
    programming
  • Reuse of an application binary code via
    component-based programming
  • OOP is a way to build object-based software
    components
  • Component-based programming is concerned with
    making objects (components) work together. The
    components may be created by many different tools

8
Benefits of Component Reuse
  • Effective use of specialists
  • Increased reliability
  • Accelerated development (Rapid Application
    Development (RAD))
  • Standards compliance
  • Reduced risks

9
Costs of Component Reuse
  • Thorough testing
  • Fully documentation
  • Robust input validity checking
  • Pass back useful error messages as appropriate
  • Maintaining a component library
  • lost in flexibility and competitive edge
  • Not-invented-here syndrome

10
Interoperability Problem and Solution
  • Different individuals develop components in their
    own way
  • How disparate components communicate with each
    other
  • We need commonly agreed mechanisms for
    interaction between components
  • Specifications, protocols and standards

11
Existing Component Technologies
  • Java Beans (Enterprise Java Beans) - Sun
    MicroSystem, written in Java
  • ActiveX and COM/DCOM - Microsoft for Windows
    platform
  • CORBA (Common Object Request Broker Architecture
    (CORBA)) - Industry consortium known as the OMG,
    or Object Management Group

12
Understanding Component Revisited
  • A component is an object written to a
    specification
  • Which specification is not important
  • Which language or on which platforms it is
    written is not important
  • An object becomes a component as long as it
    adheres to a specification

13
Microsoft Component Technologies
14
ActiveX Technologies
  • ActiveX is a framework that allows software
    components to co-operate even if they have been
    written by different vendors, at different times
    using different tools and different languages, no
    matter if the components are located in the same
    process, same machine or distributed over
    multiple machines on the Internet. Put simply,
    ActiveX provides the software plumbing between
    software objects and insulates the component
    developer from such complexities
  • ActiveX contains a set of technologies that are
    applicable for standalone applications and the
    Internet
  • ActiveX builds upon COM/DCOM

15
ActiveX Components
  • ActiveX technologies define the interfaces for
    three types of component, each of them implements
    the particular ActiveX technology
  • ActiveX controls (formerly OLE controls) (.ocx)
  • Visible component that can be dropped into an
    application at design time, esp. for GUI design
  • Code Components (.dll or .exe)
  • Usually invisible components (can contain GUI)
    that provide a service
  • ActiveX Documents (.dob)
  • Visible components (similar to forms) that
    appears within Internet browser windows

16
Component Object Model (COM)
  • The fundamental object model, or say
    specification describing how objects communicate
    with each other and also an objects life cycle
  • The core of COM are these concepts
  • Interfaces the mechanism through which an
    object exposes its functionality
  • Reference counting the technique by which an
    object decides when it is no longer being used
    and is therefore free to remove itself
  • QueryInterface the method used to query an
    object for a given interface
  • Marshaling the mechanism that enables objects
    to be used across thread, process and network
    boundaries, allowing for location independence.
  • Aggregation a way in which one object can make
    use of another.

17
Component Object Model (COM)
  • Foundation for reusable component development,
    which also provide APIs
  • Language, location, compiler and platform
    independent. Users of a component need not to
    know them
  • Several ways to package or reuse COM objects
  • .OCX, .DLLs, .EXE
  • COM objects can contain both data and methods,
    and can only be accessed by a public interface.
    Familiar?

18
Distributed COM (DCOM)
  • DCOM is an extension of the COM concepts and
    services to distributed systems
  • DCOM extends component applications across the
    Internet, so COM components can be executed on
    remote machines
  • DCOM is an open technology that runs on multiple
    platforms
  • Other features such as security and transparency
    - hiding the implementation details such as
    connecting to remote machines

19
Classes or Components?
  • Software components hide implementation, conform
    to interfaces, and encapsulate data, just like
    classes do in object-oriented languages.
  • So how do components differ from classes? Almost
    all software components are also classes. What
    makes them components is their conformance to a
    software component specification.
  • The COM Specification is the document that
    describes what a Microsoft class must do to be
    considered a component.

20
Creating ActiveX Controls in VB
21
ActiveX Controls
  • An extension to the Visual Basic Toolbox
  • A means for you to create your own controls
  • Replace VBX controls (Visual Basic extension
    controls) used in VB 4 or earlier releases
  • Build on OLE (Object Linking and Embedding)
    technology, which allows applications to work
    together seamlessly, e.g. using Excel spreadsheet
    within Word, also refers to as automation

22
ActiveX Control Types
  • User-drawn controls
  • Custom control developed from scratch
  • The most difficult type but with the most design
    flexibility
  • Enhanced controls
  • Adding extra features to existing controls
  • Aggregate controls
  • Combining one or more existing controls to form a
    new one
  • The most common control type

23
ActiveX Control Design
  • Designing an ActiveX control is as easy as
    designing a form, and can be further customised
    using property pages, name constraints and events
  • Beware that you are developing a component (a
    module) rather than an application common and
    reusable
  • Provide functions rather than provide solution to
    an application business
  • ActiveX controls can be compiled directly into
    .ocx files that can be used/reused with
    development tools

24
ActiveX Control Example
  • Create an aggregate ActiveX control called
    LabelScrollbar
  • It consists of two constituent controls, Label
    and Scrollbar
  • Functions
  • Allow a user to scroll a range of values
  • The scrollbar value is displayed as the label
    caption
  • Beware that LabelScrollbar is a single control

25
ActiveX Control Design
  • Create (Open) an ActiveX control project

26
An Open ActiveX Control Project
  • Similar to creating a Standard EXEs GUI using
    standard controls
  • ActiveX control GUI not based on Form but on
    UserControl object

UserControl1
27
UserControl Object
  • Is a container, like a form, where other controls
    can be sited
  • Has sizing handler, properties and a folder in
    the project explorer
  • Customizing a UserControl is like customizing a
    form
  • Differences from a form
  • Cannot run the UserControl directly to view its
    GUI
  • Must put the ActiveX control in a container such
    as a form

28
UserControl Object Behaviour
  • A UserControl behaves programmatically different
    from a form
  • No Activate, Load, UnLoad, QueryUnload events
  • Initialize and Terminate are similar
  • Has InitProperties, ReadProperties,
    WriteProperties, Resize events
  • Saved as .ctl file

29
UserControl Object Methods
  • InitProperties initialize a controls
    properties every time a new instance is created
    in a container, only once in a controls lifetime
  • ReadProperties set a controls properties if it
    not a new instance
  • WriteProperties persist a controls property
    value when the design time instance destroyed
    when used in an application
  • Resize specify how the constituent controls
    should size themselves when the control is resized

30
GUI Design - LabelScrollbar
  • Design the controls GUI
  • Configure properties

31
Programming Behaviour
  • Each constituent control has properties, events
    and methods
  • The UserControl object has properties, events and
    methods
  • By default, properties, events and methods of
    constituent controls are hidden within the
    UserControl object

32
Programming Behaviour
  • ActiveX control developers need to decide
  • The interface of the ActiveX control
  • Which properties or events or methods from which
    constituent control you want to expose
  • Which properties or events or methods from the
    UserControl object you want to expose
  • Any custom properties, events and methods
  • The implementation within the ActiveX control
  • The initialization, data persistence and
    termination

33
LabelScrollbar Behaviour
  • One event Change
  • Five properties, MAX, Min, LargeChange,
    SmallChange, Value
  • All are mapped to the corresponding event and
    properties in the Horizontal Scrollbar
  • Property initialization, setting, persistence and
    resizing behaviour
  • No custom properties or events but could add one,
    e.g. the space between label and the scrollbar

34
LabelScrollbar Code
  • Any events or properties the control will expose
    are placed in general declaration
  • Events or properties in general declaration must
    be public

Developers using this control will see and be
able to code this event
35
Code Examples
36
Code Example (cont.)
  • Notify the UserControls container of the change
  • Properties window updated
  • Raise the WriteProperties event

37
Raising Events in ActiveX Control
  • Constituent controls events are hidden within
    the UserControl by default
  • To expose them, must declare them as Event in
    general declaration
  • Must be coded to raise (i.e. fire) the event

38
Testing an ActiveX Control
  • Create a form as the container of the control in
    the same project
  • Run the form application to test the
    functionality of the control
  • UserControl object must be closed while testing

39
GUI Display
Form
ActiveX control Icon
40
Publishing the Control
  • Once passed the testing, a .OCX file can be
    produced for the control for distribution
  • VB provides tools for the generation of .OCX file
  • Need to remove the testing form
  • More ActiveXcontrols can be created and compiled
    into one .OCX file

41
Any Questions?
42
ActiveX Control Interface Wizard
43
Wizard Introduction
44
Selecting Interface Members
  • Select interface members events, properties and
    methods from the aggregation of all events,
    properties and methods of all constituent controls

45
LabelScrollbar Interface Members
46
Creating Own Interface Members
47
Mapping ActiveX Controls Interface Members to
Constituent Controls Interface members
48
Summary very useful
49
Code Skeleton Generated by the Wizard
50
Customize Code
  • Wizard only helps but cannot do all for you
  • Add necessary procedures and modifications
  • For LabelScrollbar example
  • Add Resize and InitProperties procedures,
  • Add code to the change event
  • Modify the default values for ReadProperties and
    WriteProperties procedures

51
Ambient Object
  • Provide the UserControl information about its
    container such as the Form
  • When an Ambient property of a container changes,
    AmbientChanged event is raised
  • UserControl_AmbientChanged event handler is
    called to handle this event
  • The handler receives a string containing the
    changed propertys name

52
Extender Object
  • Provide access to events, properties and methods
    controlled by the container your control is
    placed on
  • For the UserControl object and developers who use
    the ActiveX control

53
Property Pages
  • Allow the author of ActiveX control to group
    related properties conveniently rather than all
    in one property window
  • Allow users to view and set these properties
  • Optional for ActiveX controls, only for easy of
    use and convenience

54
Add Property Pages
55
Introduction
56
Properties Page Design
57
Grouping Properties Accordingly
58
Summary Report
59
Using Property Pages
60
Summary
  • Component based programming
  • Motivation
  • Rationale
  • ActiveX technologies
  • COM/DCOM
  • ActiveX components
  • Create ActiveX controls in VB
Write a Comment
User Comments (0)
About PowerShow.com