component-based software engineering component process

59
Component-Based Component-Based Software Software Engineering Engineering Component process Component process

Upload: horatio-johnston

Post on 28-Dec-2015

260 views

Category:

Documents


5 download

TRANSCRIPT

Page 1: Component-Based Software Engineering Component process

Component-Based Component-Based Software EngineeringSoftware Engineering

Component processComponent process

Page 2: Component-Based Software Engineering Component process

Exist ComponentExist Component

Page 3: Component-Based Software Engineering Component process

The component identification The component identification processprocess

Componentselection

Componentsearch

Componentvalidation

Page 4: Component-Based Software Engineering Component process

Connector DesignConnector Design

:Button:Button

:Button:Button

:Motor:Motor :Meter:Meter

pressed

pressed

start

stop

speed

value

Page 5: Component-Based Software Engineering Component process

Connector DesignConnector Design

:Button:Button

:Button:Button

:Motor:Motor

:Meter:Meter

pressed

pressed

start

stopspeed

value

:OR:OR:Threshold:Threshold

a

b

a b

a > b

a < b

:Multiplier:Multiplier

:Selector{1, 10, 100}

:Selector{1, 10, 100}

a b

a x b

5:int5:int

a

b

Page 6: Component-Based Software Engineering Component process

Component EngineeringComponent Engineering

For those requirements that are addressed For those requirements that are addressed with with availableavailable components, the following components, the following software engineering activities must be software engineering activities must be done:done:

1.1. Component qualificationComponent qualification

2.2. Component adaptation.Component adaptation.

3.3. Component composition. Component composition.

4.4. Component update. Component update.

Page 7: Component-Based Software Engineering Component process

Component qualificationComponent qualification

Component qualification ensures that a Component qualification ensures that a candidate component candidate component will perform the function required, will perform the function required, will properly fit into the architectural style will properly fit into the architectural style

specified for the system, and specified for the system, and will exhibit the quality characteristics will exhibit the quality characteristics

(e.g., performance, reliability, usability) (e.g., performance, reliability, usability) required for the application.required for the application.

Page 8: Component-Based Software Engineering Component process

Component adaptationComponent adaptation

In some cases, existing components In some cases, existing components may be mismatched to the may be mismatched to the architecture’s design rules. These architecture’s design rules. These components must be components must be adaptedadapted to meet to meet the needs of the architecture the needs of the architecture

adaptation technique called adaptation technique called “component “component wrappingwrapping” is often used. ” is often used.

Page 9: Component-Based Software Engineering Component process

Component adaptation--wrappingComponent adaptation--wrapping When a software team has full access to the When a software team has full access to the

internal design and code for a component, internal design and code for a component, white-white-boxbox wrapping is applied. This wrapping examines wrapping is applied. This wrapping examines the internal processing details and makes code-the internal processing details and makes code-level modifications to remove any conflicts. level modifications to remove any conflicts.

Grey-boxGrey-box wrapping is applied when the component wrapping is applied when the component library provides a component extension language or library provides a component extension language or API that enables conflicts to be removed or API that enables conflicts to be removed or masked.masked.

Black-boxBlack-box wrapping requires the introduction of pre- wrapping requires the introduction of pre- and post-processing at the component interface to and post-processing at the component interface to remove or mask conflicts.remove or mask conflicts.

Page 10: Component-Based Software Engineering Component process

Component compositionComponent composition

The process of assembling The process of assembling components to create a system.components to create a system.

Composition involves integrating Composition involves integrating components with each other and components with each other and with the component with the component infrastructure.infrastructure.

Page 11: Component-Based Software Engineering Component process

Types of compositionTypes of composition Sequential composition Sequential composition where the composed where the composed

components are executed in sequence. This components are executed in sequence. This involves composing the provides interfaces of involves composing the provides interfaces of each component.each component.

Hierarchical composition Hierarchical composition where one where one component calls on the services of another. component calls on the services of another. The provides interface of one component is The provides interface of one component is composed with the requires interface of composed with the requires interface of another.another.

Additive composition Additive composition where the interfaces of where the interfaces of two components are put together to create a two components are put together to create a new component.new component.

Page 12: Component-Based Software Engineering Component process

Types of compositionTypes of composition

(a)

A A

B B

A B

(b) (c)

Page 13: Component-Based Software Engineering Component process

Interface incompatibilityInterface incompatibility

Parameter incompatibility Parameter incompatibility where operations where operations have the same name but are of different have the same name but are of different types.types.

Operation incompatibility Operation incompatibility where the names where the names of operations in the composed interfaces are of operations in the composed interfaces are different.different.

Operation incompleteness Operation incompleteness where the where the provides interface of one component is a provides interface of one component is a subset of the requires interface of another.subset of the requires interface of another.

Page 14: Component-Based Software Engineering Component process

Incompatible componentsIncompatible components

addressFinder

phoneDatabase (string command)string location(string pn)

string owner (string pn)

string propertyType (string pn)

mapper

mapDB (string command)displayMap (string postCode, scale)

printMap (string postCode, scale)

Page 15: Component-Based Software Engineering Component process

Composition through an Composition through an adaptoradaptor

The component postCodeStripper is the The component postCodeStripper is the adaptor that facilitates the sequential adaptor that facilitates the sequential composition of addressFinder and mapper composition of addressFinder and mapper components.components.

Page 16: Component-Based Software Engineering Component process

Adaptor for data collectorAdaptor for data collector

Data collector

addSensorremoveSensorstartSensor

stopSensortestSensor

listAllreportinitialise

sensorManagement

sensorData

Adaptersensor

start

getdata

stop

Page 17: Component-Based Software Engineering Component process

Photo library compositionPhoto library composition

PhotoLibrary

adaptorImage

Manager

getImage

UserInterface

getCatalogEntry

addItem

retrieve

catEntry

Page 18: Component-Based Software Engineering Component process

Component updateComponent update

When systems are implemented with When systems are implemented with components, update is complicated components, update is complicated by the imposition of a third party. The by the imposition of a third party. The organization that developed the organization that developed the reusable component may be outside reusable component may be outside the immediate control of the software the immediate control of the software engineering organization.engineering organization.

Page 19: Component-Based Software Engineering Component process

New ComponentNew Component

Page 20: Component-Based Software Engineering Component process

Again, What is a component ?Again, What is a component ?

A component makes its A component makes its services available through services available through interfaces and interfaces are of interfaces and interfaces are of certain types or categoriescertain types or categories

Page 21: Component-Based Software Engineering Component process

Printing Services ComponentPrinting Services Component

Provides interfaceRequires interface

Print

PrintService

GetQueue

Remove

Transfer

Register

Unregister

GetPDfile

PrinterInt

Page 22: Component-Based Software Engineering Component process

Component AbstractionsComponent Abstractions

Functional abstractionFunctional abstraction The component implements a single function such as a The component implements a single function such as a

mathematical functionmathematical function

Data abstractionsData abstractions The component represents a class in an object-oriented languageThe component represents a class in an object-oriented language

Cluster abstractionsCluster abstractions The component is a group of related classes that work togetherThe component is a group of related classes that work together

System abstractionSystem abstraction The component is an entire self-contained systemThe component is an entire self-contained system

Page 23: Component-Based Software Engineering Component process

2323

New ComponentNew Component

To design and develop the internals of a To design and develop the internals of a components we distinguish four levels of components we distinguish four levels of abstractionabstraction

• Component specificationComponent specification• Component implementationComponent implementation• Component executableComponent executable• Component deploymentComponent deployment

The process can be carried out using techniques The process can be carried out using techniques like UML and OO programming languages, and like UML and OO programming languages, and methodologies supporting component methodologies supporting component production. production.

Page 24: Component-Based Software Engineering Component process

Component SpecificationComponent Specification

Provides InterfacesProvides Interfaces The services a component can offer to a clientThe services a component can offer to a client

Requires InterfacesRequires Interfaces The services required by a component to help The services required by a component to help

it deliver its promisesit deliver its promises Context of UseContext of Use

The “world” the component lives inThe “world” the component lives in

Page 25: Component-Based Software Engineering Component process

2525

Component implementationComponent implementation

It defines the inside of a component, with It defines the inside of a component, with its internal parts and collaborations. its internal parts and collaborations.

It occurs after the decision of the It occurs after the decision of the programming language to use for the programming language to use for the developmentdevelopment

It must satisfies the specificationIt must satisfies the specification One-to-many relationshipOne-to-many relationship

Page 26: Component-Based Software Engineering Component process

2626

Component executableComponent executable

It is the real It is the real pluggable pluggable component used in component used in the assembly of the applicationthe assembly of the application

Each executable may results in more than Each executable may results in more than one versionone version There may be more than one executable per There may be more than one executable per

implementationimplementation

Page 27: Component-Based Software Engineering Component process

2727

Component deploymentComponent deployment

It is the deployment of the component It is the deployment of the component executable on a number of nodesexecutable on a number of nodes

There may be several deployment for the There may be several deployment for the same executable.same executable.

Page 28: Component-Based Software Engineering Component process

Component Programming Component Programming with C# and .NETwith C# and .NET

Page 29: Component-Based Software Engineering Component process

C# componentsC# components

The most commonly used components The most commonly used components in .NET are the visual controls that you in .NET are the visual controls that you add to Windows Forms such as the add to Windows Forms such as the Button Control (Windows Forms), , ComboBox Control (Windows Forms), and , and so on. so on.

Non-visual components include the Non-visual components include the Timer Control, , SerialPort, and , and ServiceController among others. among others.

Page 30: Component-Based Software Engineering Component process

What defines a component?What defines a component?

What defines a component in C#?What defines a component in C#? Properties, methods, eventsProperties, methods, events Design-time and runtime Design-time and runtime

informationinformation Integrated help and documentationIntegrated help and documentation

Page 31: Component-Based Software Engineering Component process

AP 08/01AP 08/01

public class Button: Controlpublic class Button: Control{{ private string caption;private string caption;

public string Caption {public string Caption { get {get { return caption;return caption; }} set {set { caption = value;caption = value; Repaint();Repaint(); }} }}}}

PropertiesProperties Properties are “smart fields”Properties are “smart fields”

Natural syntax, accessors, inliningNatural syntax, accessors, inlining

Button b = new Button();Button b = new Button();b.Caption = "OK";b.Caption = "OK";

String s = b.Caption;String s = b.Caption;

Page 32: Component-Based Software Engineering Component process

AP 08/01AP 08/01

IndexersIndexers Indexers are “smart arrays”Indexers are “smart arrays”

Can be overloadedCan be overloaded

public class ListBox: Control{ private string[] items;

public string this[int index]{ get { return items[index]; } set { items[index] = value; Repaint(); } }}

ListBox listBox = new ListBox();ListBox listBox = new ListBox();listBox[0] = "hello";listBox[0] = "hello";Console.WriteLine(listBox[0]);Console.WriteLine(listBox[0]);

Page 33: Component-Based Software Engineering Component process

AP 08/01AP 08/01

EventsEvents Efficient, type-safe and customizable Efficient, type-safe and customizable

Built on delegates Built on delegates

public class MyForm: Form { public MyForm() { Button okButton = new Button(...);

okButton.Click += new EventHandler(OkButtonClick); }

void OkButtonClick(…) { ShowMessage("You clicked OK"); }}

Page 34: Component-Based Software Engineering Component process

EventsEvents

Events enable a Events enable a class or object to notify  or object to notify other classes or objects when something other classes or objects when something of interest occursof interest occurs

The class that sends (or raises) the event The class that sends (or raises) the event is called the publisher and the classes that is called the publisher and the classes that receive (or handle) the event are receive (or handle) the event are called subscribers.called subscribers.

Page 35: Component-Based Software Engineering Component process

ExampleExample

Arithmetic component which does additionArithmetic component which does addition We will create a component called We will create a component called

CSAddComp1CSAddComp1 and package it into a dll and package it into a dll (Dynamic Linked Library). (Dynamic Linked Library).

This component has two properties and a This component has two properties and a method. method.

Properties take input for the addition and Properties take input for the addition and method called Sum( ).method called Sum( ).

Page 36: Component-Based Software Engineering Component process

ExampleExample

To create properties in C# you use To create properties in C# you use the get and set accessors. the get and set accessors.

The get accessor is used for getting The get accessor is used for getting (reading). (reading).

The set accessor for setting (writing) The set accessor for setting (writing) the propertythe property

Page 37: Component-Based Software Engineering Component process

Component ProgramComponent Programusing System; using System;

namespace CompCS { namespace CompCS {

public class CSAddComp1 { public class CSAddComp1 {

private int varI=0,varJ=0; private int varI=0,varJ=0;

public int varI { get { return varI; } //this is property get for varI public int varI { get { return varI; } //this is property get for varI

set { varI=value; } //this is property set for varI set { varI=value; } //this is property set for varI

} }

public int varJ { public int varJ {

get { return varJ; } // this is property get for varJ get { return varJ; } // this is property get for varJ

set { varJ=value; } // this is property set for varJ set { varJ=value; } // this is property set for varJ

} }

public int Sum() { public int Sum() {

return varI+varJ; return varI+varJ; //this returns the sum of two variables//this returns the sum of two variables

} } //end of class} } //end of class

} //end of namespace} //end of namespace

Page 38: Component-Based Software Engineering Component process

DLL package DLL package  To package the component as To package the component as dlldll there is slight there is slight

change in usual compilation process. change in usual compilation process. Its little complicated process when compared to Its little complicated process when compared to

normal stand-alone program compilation.normal stand-alone program compilation.csc /out:CSAddComp1.dll /target:library CSAddComp1.cscsc /out:CSAddComp1.dll /target:library CSAddComp1.cs

Here the /out switch to put the compiled component Here the /out switch to put the compiled component in the relative subdirectory and file for convenience. in the relative subdirectory and file for convenience.

Likewise, we need the /target:library switch to Likewise, we need the /target:library switch to actually create a DLL rather than an executable actually create a DLL rather than an executable with a .dll file extension.with a .dll file extension.

Page 39: Component-Based Software Engineering Component process

  client programclient programusing System; using System;

using CompCS; using CompCS;

class clAddComp1 { class clAddComp1 {

public static void Main() { public static void Main() {

CSAddComp1 addComp= new CSAddComp1(); CSAddComp1 addComp= new CSAddComp1();

addComp.varI=10; addComp.varI=10; //property set for varI //property set for varI

addComp.varJ=20; addComp.varJ=20; //property set for varJ //below property get for varI //property set for varJ //below property get for varI

Console.WriteLine("variable I value : {0}",addComp.varI); Console.WriteLine("variable I value : {0}",addComp.varI); //below property get //below property get for varJfor varJ

Console.WriteLine("variable J value : {0}",addComp.varJ); Console.WriteLine("variable J value : {0}",addComp.varJ); // calling Sum(..) // calling Sum(..) methodmethod

Console.WriteLine("The Sum : {0}",addComp.Sum()); Console.WriteLine("The Sum : {0}",addComp.Sum());

} //end of Main } //end of Main

} // end of Class} // end of Class

Page 40: Component-Based Software Engineering Component process

Component DesignerComponent Designer in C# in C#

To display the designer, from the To display the designer, from the ProjectProject menu,  menu, select select Add ComponentAdd Component. .

The The Add New ItemAdd New Item dialog box appears.  dialog box appears. By default, the By default, the Component ClassComponent Class item is selected.  item is selected. Click Click OKOK to add a new component to project and  to add a new component to project and

open the open the Component DesignerComponent Designer.. http://www.youtube.com/watch?v=DgAqyYO20nY

Page 41: Component-Based Software Engineering Component process

As an example, to package the alarm functionality we built the Timer component, let's build anAlarmComponent class. To create a new component class, right-click on the project and choose Add | Add Component, enter the name of your component class, and press OK. You'll be greeted with a blank design surface,

Page 42: Component-Based Software Engineering Component process
Page 43: Component-Based Software Engineering Component process

using System; using System;

using System.ComponentModel; using System.ComponentModel;

using System.Collections; using System.Collections;

using System.Diagnostics;   using System.Diagnostics;  

namespace Components {namespace Components {

public class AlarmComponent : System.ComponentModel.Component { public class AlarmComponent : System.ComponentModel.Component {

private Timer timer1; private Timer timer1;

private System.ComponentModel.IContainer components;   private System.ComponentModel.IContainer components;  

public AlarmComponent(System.ComponentModel.IContainer container) { public AlarmComponent(System.ComponentModel.IContainer container) {

container.Add(this); container.Add(this);

InitializeComponent();   InitializeComponent();  

}  }  

public AlarmComponent() {public AlarmComponent() {

InitializeComponent();   }   InitializeComponent();   }  

private void InitializeComponent() { private void InitializeComponent() {

this.components = new System.ComponentModel.Container(); this.components = new System.ComponentModel.Container();

this.timer1 = new System.Windows.Forms.Timer(this.components); this.timer1 = new System.Windows.Forms.Timer(this.components);

this.timer1.Enabled = true; }}}this.timer1.Enabled = true; }}}

Page 44: Component-Based Software Engineering Component process

AttributesAttributes

We can use attributes to define both We can use attributes to define both design-level information (such as help design-level information (such as help file, URL for documentation) and run-file, URL for documentation) and run-time information (such as associating time information (such as associating XML field with class field). XML field with class field).

We can also create "self-describing" We can also create "self-describing" components using attributes. components using attributes.

Page 45: Component-Based Software Engineering Component process

AttributesAttributes

[HelpUrl(“http://SomeUrl/Docs/SomeClass”)]class SomeClass{ [WebMethod] void GetCustomers() { … }

string Test([SomeAttr] string param1) {…}}

Appear in square bracketsAppear in square brackets Attached to code elementsAttached to code elements

Page 46: Component-Based Software Engineering Component process

Apply attributesApply attributes

Define a new attribute or use an existing Define a new attribute or use an existing attribute by importing its namespace from attribute by importing its namespace from the .NET Framework.the .NET Framework.

Page 47: Component-Based Software Engineering Component process

ExampleExampleusing System; using System;

public class AnyClass { public class AnyClass { [Obsolete("Don't use Old method, use New method", true)]

static void Old( ) { } static void Old( ) { }

static void New( ) { } static void New( ) { }

public static void Main( ) public static void Main( )

{ {

Old( ); Old( );

} }} }

Page 48: Component-Based Software Engineering Component process

ExampleExample we use attribute Obsolete, which marks a we use attribute Obsolete, which marks a

program entity that should not be used. program entity that should not be used. The first parameter is the string that can be The first parameter is the string that can be

any text. any text. The second parameter tells the compiler to The second parameter tells the compiler to

treat the use of the item as an error. treat the use of the item as an error. Default value is false, which means compiler Default value is false, which means compiler

generates a warning for this.generates a warning for this.

Page 49: Component-Based Software Engineering Component process

Attribute Fundamentals Attribute Fundamentals

Attributes are classes! Completely genericAttributes are classes! Completely generic

class HelpUrl : System.Attribute { public HelpUrl(string url) { … } …}

[HelpUrl(“http://SomeUrl/APIDocs/SomeClass”)]class SomeClass { … }

Page 50: Component-Based Software Engineering Component process

Attributes to specify Attributes to specify DLL ImportDLL Importss

[DllImport("gdi32.dll",CharSet=CharSet.Auto)]public static extern int GetObject( int hObject,

int nSize, [In, Out] ref LOGFONT lf);

[DllImport("gdi32.dll")]public static extern int CreatePen(int style, int width, int color);

Page 51: Component-Based Software Engineering Component process

Component & attributesComponent & attributes components can be displayed in a designer, such as components can be displayed in a designer, such as

Visual Studio .NET, but required attributes that provide Visual Studio .NET, but required attributes that provide metadata to design-time tools.metadata to design-time tools.

AA DesignerAttribute DesignerAttribute attribute is applied at the class  attribute is applied at the class level and informs the forms designer which designer level and informs the forms designer which designer class to use to display the control. class to use to display the control.

Components are associated with a default designer Components are associated with a default designer ((System.ComponentModel.Design.ComponentDesigSystem.ComponentModel.Design.ComponentDesignerner), and Windows Forms and ASP.NET server controls ), and Windows Forms and ASP.NET server controls are associated with their own default designers. are associated with their own default designers.

Apply Apply DesignerAttributeDesignerAttribute only if you define a custom  only if you define a custom designer for your component or control.designer for your component or control.

Page 52: Component-Based Software Engineering Component process

To add a security attribute to a code member of your component

using System.Security.Permissions; using System.Security.Permissions;

[FileIOPermission(SecurityAction.Demand)] [FileIOPermission(SecurityAction.Demand)]

public void FileDeleter() public void FileDeleter()

{ // Insert code to delete files. }{ // Insert code to delete files. }

Page 53: Component-Based Software Engineering Component process

COM SupportCOM Support

.NET Framework provides great COM .NET Framework provides great COM support support TLBIMP imports existing COM classesTLBIMP imports existing COM classes TLBEXP exports .NET types TLBEXP exports .NET types

Most users will have a seamless experienceMost users will have a seamless experience

Page 54: Component-Based Software Engineering Component process

Building COM components using.NET Framework

Create C# - Class Library projectCreate C# - Class Library project Develop the AccountManager.cs libraryDevelop the AccountManager.cs library Modify the generated AssemblyInfo.cs to add the Modify the generated AssemblyInfo.cs to add the

right assembly informationright assembly information Build the Project FilesBuild the Project Files Deploy the component as a Shared Assembly, and Deploy the component as a Shared Assembly, and

Configure the Assembly in the COM+ CatalogConfigure the Assembly in the COM+ Catalog

Page 55: Component-Based Software Engineering Component process
Page 56: Component-Based Software Engineering Component process

Configure your Project Property Pages with the right information

Page 57: Component-Based Software Engineering Component process
Page 58: Component-Based Software Engineering Component process

add the right assembly information

[assembly: AssemblyTitle([assembly: AssemblyTitle("AccountManager for Bank""AccountManager for Bank")])][assembly: AssemblyDescription([assembly: AssemblyDescription("Creates and Deletes "Creates and Deletes Accounts for the Bank"Accounts for the Bank")])][assembly: AssemblyConfiguration([assembly: AssemblyConfiguration("""")])][assembly: AssemblyCompany([assembly: AssemblyCompany("eCommWare "eCommWare Corporation"Corporation")])][assembly: AssemblyProduct([assembly: AssemblyProduct("COM+ Bank Server""COM+ Bank Server")])][assembly: AssemblyCopyright([assembly: AssemblyCopyright("(c) 2001, Gopalan "(c) 2001, Gopalan Suresh Raj. All Rights Reserved."Suresh Raj. All Rights Reserved.")])][assembly: AssemblyTrademark([assembly: AssemblyTrademark("Web Cornucopia""Web Cornucopia")])][assembly: AssemblyCulture([assembly: AssemblyCulture("en-US""en-US")])]

Page 59: Component-Based Software Engineering Component process

Calling into a COM componentCalling into a COM component

Create .NET assembly from COM component via Create .NET assembly from COM component via tlbimptlbimp Client apps may access the newly created assemblyClient apps may access the newly created assembly

using System;using System.Runtime.InteropServices;

using CONVERTERLib;

class Convert {public static void Main(string [] args) {CFConvert conv = new CFConvert();...fahrenheit = conv.CelsiusToFahrenheit( celsius );