component-based software engineering component definition

62
Component-based software engineering Component definition

Upload: kerry-gray

Post on 28-Dec-2015

241 views

Category:

Documents


5 download

TRANSCRIPT

Page 1: Component-based software engineering Component definition

Component-based software engineering

Component definition

Page 2: Component-based software engineering Component definition

What is a Component?

We can find several definitions of a component in literature, however everyone agrees that a component is a piece of software.

Page 3: Component-based software engineering Component definition

Component everywhere Concerns and goals are similar in many engineering

disciplines• Precise assembly of reusable, well-documented, quality

and trusted parts

For them components are well established• Civil engineering -> house prefab, …• Chemical engineering-> proteins, …• Electronic engineering-> circuit,…• Industrial engineering -> cars, …

Page 4: Component-based software engineering Component definition

Example: the automobile

Car assembly was a costly, tedious and slow process

Henry Ford life’s goal:• Produce cars for the masses by building them

faster Ford’s method

• The assembly line (1914)• Idea by reversing the process of beef- trolleys:

butchers removed cuts from the carcass passed by until nothing remained.

Page 5: Component-based software engineering Component definition

Component-based development

Component-based software engineering (CBSE) is an approach to software development that relies on software reuse.

It emerged from the failure of object-oriented development to support effective reuse.

Single object classes are too detailed and specific.

Components are more abstract than object classes and can be considered to be stand-alone service providers.

Page 6: Component-based software engineering Component definition

Reusable Component Example

Linked list of elements where each element maintains a pointer to the next element in the list.

Page 7: Component-based software engineering Component definition

Objects and Components

Pfister and Szyperski• View a component as a collection of objects,

in which the objects co-operate with each other, and are intertwined tightly.

D'Souza and Wills • Assert that if a class were packaged together

with the explicitly defined interfaces which it requires and implements, then this class would be a component.

Page 8: Component-based software engineering Component definition

Objects and Components Continued

Components have a more extensive set of intercommunication mechanisms than objects which usually use the messaging mechanism.

Components are often larger units of granularity than objects, and have complex actions at their interfaces.

Page 9: Component-based software engineering Component definition

Component definitions Councill and Heinmann:

• A software component is a software element that conforms to a component model and can be independently deployed and composed without modification according to a composition standard.

Szyperski:• A software component is a unit of composition

with contractually specified interfaces and explicit context dependencies only. A software component can be deployed independently and is subject to composition by third-parties.

Page 10: Component-based software engineering Component definition

What is not a component

The requirement for independence rules out• Type declarations• C macros• C++ templates• Smalltalk blocks

Page 11: Component-based software engineering Component definition

What could be a component

Procedures Libraries Classes (not objects) Modules Web browsers’ plug-ins

Page 12: Component-based software engineering Component definition

Examples NASA software

• 25 software product ranged from 3000 to 112000 lines of source code

• 7188 components classified into 4 classes• Component used without changes• Components reused with slight revisions less than

25%• Components reused with major revisions • Components reused with developing rom scratch

Page 13: Component-based software engineering Component definition

Case study Document editor

• Create new document• Open, save, and print document• Cut selected text from document• Change font and style of text• Change formatting of text• Check spelling• ……

Page 14: Component-based software engineering Component definition
Page 15: Component-based software engineering Component definition
Page 16: Component-based software engineering Component definition

CBSE and design principles Apart from the benefits of reuse, CBSE is

based on sound software engineering design principles:• Components are independent so do not

interfere with each other;• Component implementations are hidden;• Communication is through well-defined

interfaces;• Component platforms are shared and

reduce development costs.• Components are language-independent.

Page 17: Component-based software engineering Component definition

Describing a Component

To be able to describe a component completely the component should consist of the following elements: • A set of interfaces provided to, or

required from the environment.

• An executable code, which can be coupled to the code of other components via interfaces.

Page 18: Component-based software engineering Component definition

Interfaces

A component interface define mean to connect a component

In a component based application providers and clients are ignorant of each other

A component can have multiple interfaces• To offer multiple services (possibly with

overlapping functionalities)• To allow for multiple versions to live together

Page 19: Component-based software engineering Component definition

Component interfaces

Provides interface

• Defines the services that are provided by the

component to other components (deployment

environment).

Requires interface

• Defines the needs that specifies what services

must be made available for the component to

execute as specified.

Page 20: Component-based software engineering Component definition

Component interfaces

Page 21: Component-based software engineering Component definition

A data collector component

Provides interfaceRequires interface

Data collector

addSensorremoveSensorstartSensor

stopSensor

testSensor

listAllreport

initialise

sensorManagement

sensorData

Page 22: Component-based software engineering Component definition

Indirect interface An indirect interface uses a technique called dispatch

which can lead to involvement of a third party which might be unknown to both client and the provider

Text services class

Word processing comp. Grammar checking comp.

Word processor class Grammar checker class

Text services component

Checker interface

Has-aHas-a Has-a Implements

Page 23: Component-based software engineering Component definition

Contracts A more accurate specification of a component's

behavior can be achieved through contracts. A contract is comprised of:

• The Invariant, the global constraints which the component will maintain;

• The Pre-condition, the constraints which need to be met by the client;

• The Post-condition, the constraints which the component promises to establish in return.

Page 24: Component-based software engineering Component definition

How can we write a contract Hoare triples {Pre} operation {Post}

• Partial correctness• Total correctness

Temporal logic• Progress (leads-to, eventually)• Safety (Invariants, always)• Fairness (eventually always)

With time and space bounds• Average cases• Together with platform-dependent measurments

Informally, in precise but plain English• Several interpretations can be found• Analogy with real-world laws

Page 25: Component-based software engineering Component definition

Formal description of photo library

Page 26: Component-based software engineering Component definition

Software Frameworks CBSE means that we build software by

"putting pieces together". Frameworks provide the context in which the pieces can be used.

A framework may be seen as:• A reusable design of a system, • A skeleton of an application which can be

customized by an application developer.

Page 27: Component-based software engineering Component definition

Component Frameworks

While frameworks in general describe a typical and reusable situation at a model level,

a component framework describes a “circuit-board” with empty slots into which components can be inserted to create a working instance.

Coordination Services (transactions, persistence..)

ComponentFramework

Page 28: Component-based software engineering Component definition

Frameworks and Contracts

Frameworks and Contracts• Frameworks focus on the overall

properties of component compositions. • Contracts give specifications for

relationships between concrete components.

These specifications may be different for components within one composition.

Page 29: Component-based software engineering Component definition

Patterns Patterns define recurring solutions to

recurring problems capturing non-obvious solutions, not just abstract principles or strategies.

• The solutions should be proven to solve the problem rather than being theories.

• Patterns describe relationships between deeper system structures and mechanism.

• A component, as a reusable entity, can be seen as a realization of some design pattern.

Page 30: Component-based software engineering Component definition

Three Categories of Patterns Patterns can be classified into three major

categories:

• Architectural Patterns, capture the overall structure and organization of a software system.

• Design Patterns, refine the structure and the behavior of the subsystems as well as the components of a software system, and the relationships which exist between them.

• Idioms, are low-level patterns which are dependent on the chosen paradigm and the programming language used.

Page 31: Component-based software engineering Component definition

Design Patterns

Design patterns are widely used in the process of designing component-based systems in which the reusable units must be identified.

By using design patterns, it is easier to recognize those reusable parts and either find them in the form of pre-existing components, or develop them as reusable units.

Page 32: Component-based software engineering Component definition

Component models A component model is a definition of

standards for component implementation, documentation and deployment.

The component model specifies how interfaces should be defined and the elements that should be included in an interface definition.

Examples of component models• EJB model (Enterprise Java Beans)• COM+ model• Corba Component Model

Page 33: Component-based software engineering Component definition

Component Technologies Corba - Common Object Requesting Broker

Architecture• Map the IDL language to your native language

Microsoft’s COM• Binary Type System• Metadata• Interface or contract based – the unit of reuse.

• Resort to IUnknown interface

• Runtime-loading – allows copy and paste of objects. Enterprise JavaBeans .NET Remoting

Page 34: Component-based software engineering Component definition

Elements of a component model

Component model

InterfacesUsage

informationDeployment

and use

Interfacedefinition

Specificinterfaces

Composition

Namingconvention

Meta-dataaccess

Customisation

Packaging

Documentation

Evolutionsupport

Page 35: Component-based software engineering Component definition

The CBSE process

Identify candidatecomponents

Outlinesystem

requirements

Modifyrequirements

according to discoveredcomponents

Identify candidatecomponents

Architecturaldesign

Composecomponents tocreate system

Page 36: Component-based software engineering Component definition

The component identification process

Componentselection

Componentsearch

Componentvalidation

Page 37: Component-based software engineering Component definition

Component identification issues Trust. You need to be able to trust the supplier of

a component. At best, an untrusted component may not operate as advertised; at worst, it can breach your security.

Requirements. Different groups of components will satisfy different requirements.

Validation. • The component specification may not be detailed

enough to allow comprehensive tests to be developed.

• Components may have unwanted functionality. How can you test this so it will not interfere with your application?

Page 38: Component-based software engineering Component definition

Component composition

The process of assembling components to create a system.

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

Page 39: Component-based software engineering Component definition

Types of composition Sequential composition where the composed

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

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

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

Page 40: Component-based software engineering Component definition

Types of composition

(a)

A A

B B

A B

(b) (c)

Page 41: Component-based software engineering Component definition

Incompatible 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 42: Component-based software engineering Component definition

Adaptor components

Address the problem of component incompatibility by reconciling the interfaces of the components that are composed.

An addressFinder and a mapper component may be composed through an adaptor that strips the postal code from an address and passes this to the mapper component.

Page 43: Component-based software engineering Component definition

Composition through an adaptor The component postCodeStripper is the adaptor

that facilitates the sequential composition of addressFinder and mapper components.

Page 44: Component-based software engineering Component definition

Adaptor for data collector

Data collector

addSensorremoveSensorstartSensor

stopSensortestSensor

listAllreportinitialise

sensorManagement

sensorData

Adaptersensor

start

getdata

stop

Page 45: Component-based software engineering Component definition

Photo library composition

PhotoLibrary

adaptorImage

Manager

getImage

UserInterface

getCatalogEntry

addItem

retrieve

catEntry

Page 46: Component-based software engineering Component definition

Photo library Case study the Photo Library component states that:

• There must not be a photograph in the library with the same identifier as the photograph to be entered;

• The library must exist - assume that creating a library adds a single item to it;

• Each new entry increases the size of the library by 1;• If you retrieve using the same identifier then you get

back the photo that you added;• If you look up the catalogue using that identifier, then

you get back the catalogue entry that you made.

Page 47: Component-based software engineering Component definition

Formal description of photo library

Page 48: Component-based software engineering Component definition

Reusable Component Example

Linked list of elements where each element maintains a pointer to the next element in the list.

Page 49: Component-based software engineering Component definition

Class Templates Many C++ programs use common data structures

like stacks, queues and lists. A program may require a queue of customers and a

queue of messages. One could easily implement a queue of customers, then take the existing code and implement a queue of messages.

It seems to make more sense to implement a queue that can contain any arbitrary type.

Page 50: Component-based software engineering Component definition

Class Templates How does one do that? The answer is to use type

parameterization, more commonly referred to as templates.

C++ templates allow one to implement a generic Queue<T> template that has a type parameter T.

T can be replaced with actual types Once the changes are implemented in the template

Queue<T>, they are immediately reflected in the classes Queue<Customers>, Queue<Messages>, and Queue<Orders>.

Page 51: Component-based software engineering Component definition

C++ Class Templates

C++ provides two kinds of templates: class templates and function templates.

Use function templates to write generic functions that can be used with arbitrary types.

For example, one can write searching and sorting routines which can be used with any arbitrary type.

Page 52: Component-based software engineering Component definition

C++ Class Templatestemplate <class T>

class Stack {

public:

Stack(int = 10) ;

~Stack() { delete [] stackPtr ; }

int push(const T&);

int pop(T&) ;

int isEmpty()const { return top == -1 ; }

int isFull() const { return top == size - 1 ; }

private:

int size ; // number of elements on Stack.

int top ;

T* stackPtr ; } ;

Page 53: Component-based software engineering Component definition

C++ Function Templates

#include <iostream>

using namespace std ; //max returns the maximum of the two elements

template <class T>

T max(T a, T b)

{ return a > b ? a : b ; }

Page 54: Component-based software engineering Component definition

C++ Linked List

template <class elem> class List{public:

List(); // Automatic constructor~List(); // Automatic destructor// Basic list operationselem Head (error_indic &Err) ; int Length ( ) ;List <elem> Tail (error_indic &Err) ;// Equality operationsfriend List <elem> operator == (List <elem> L1, List <elem> L2) ;friend List <elem> Equivalent (List <elem> L1, List <elem> L2) ;// Constructor operations for linked listvoid Append (elem E, error_indic &Err) ;

void Add (elem E, error_indic &Err) ; void Add_before (elem E, error_indic &Err) ; void Add_after (elem E, error_indic &Err) ; void Replace (elem E, error_indic &Err) ; void Clear (error_indic &Err ) ; void Prune (error_indic &Err ) ; void Prune_to (elem E, error_indic &Err ) ; void Prune_from (elem E, error_indic &Err ) ; void Remove (elem E, error_indic &Err ) ; void Remove_before (elem E, error_indic &Err ) ; void Remove_after (elem E, error_indic &Err ) ;

Page 55: Component-based software engineering Component definition

C++ Linked List

// I/O functionsvoid Print(error_indic &Err) ;

void Write_list(char* filename, error_indic &Err) ; void Read_list(char* filename, error_indic &Err) ;private:

typedef struct Linkedlist { elem val; Linkedlist* next; } Linkedlist;

Linkedlist* Listhead ; // (Internal) Pointer to start of list};

template <class elem> class Iterator { friend class List <elem> ;public: Iterator () ; ~Iterator () ; void Create (List <elem> L, error_indic &Err) ; void Go_next (error_indic &Err) ; elem Eval (error_indic &Err) ; boolean At_end () ;private: Linkedlist* iter ;} ;

Page 56: Component-based software engineering Component definition

C# components

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

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

Page 57: Component-based software engineering Component definition

What defines a component?

What defines a component?• Properties, methods, events

• Design-time and runtime information

• Integrated help and documentation

Page 58: Component-based software engineering Component definition

AP 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(); }} }}}}

Properties Properties are “smart fields”

• Natural 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 59: Component-based software engineering Component definition

AP 08/01

Indexers Indexers are “smart arrays”

• Can 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 60: Component-based software engineering Component definition

AP 08/01

Events Efficient, type-safe and customizable

• 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 61: Component-based software engineering Component definition

Events

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

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

Page 62: Component-based software engineering Component definition

Projects

http://www.fuka.info.waseda.ac.jp/Project/CBSE/metrics.html

http://www.fuka.info.waseda.ac.jp/Project/CBSE/fukabeans/