Presentation is loading. Please wait.

Presentation is loading. Please wait.

Component-based software engineering

Similar presentations


Presentation on theme: "Component-based software engineering"— Presentation transcript:

1 Component-based software engineering
Component definition

2 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.

3 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, …

4 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.

5 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.

6 Reusable Component Example
Linked list of elements where each element maintains a pointer to the next element in the list.

7 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.

8 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.

9 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.

10 What is not a component The requirement for independence rules out
Type declarations C macros C++ templates Smalltalk blocks

11 What could be a component
Procedures Libraries Classes (not objects) Modules Web browsers’ plug-ins

12 Examples NASA software
25 software product ranged from 3000 to 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

13 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 ……

14

15

16 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.

17 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.

18 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

19 Component interfaces Provides interface Requires 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.

20 Component interfaces

21 A data collector component

22 Text services component
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 Word processing comp. Grammar checking comp. Word processor class Grammar checker class Has-a Has-a Implements Has-a Text services class Checker interface Text services component

23 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.

24 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

25 Formal description of photo library

26 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.

27 Coordination Services (transactions, persistence..)
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. Component Framework Coordination Services (transactions, persistence..)

28 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.

29 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.

30 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.

31 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.

32 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

33 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

34 Elements of a component model

35 The CBSE process

36 The component identification process

37 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?

38 Component composition
The process of assembling components to create a system. Composition involves integrating components with each other and with the component infrastructure.

39 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.

40 Types of composition

41 Incompatible components

42 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.

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

44 Adaptor for data collector

45 Photo library composition

46 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.

47 Formal description of photo library

48 Reusable Component Example
Linked list of elements where each element maintains a pointer to the next element in the list.

49 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.

50 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>.

51 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.

52 C++ Class Templates template <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 ; } ;

53 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 ; }

54 C++ Linked List template <class elem> class List { public:
List(); // Automatic constructor ~List(); // Automatic destructor // Basic list operations elem Head (error_indic &Err) ; int Length ( ) ; List <elem> Tail (error_indic &Err) ; // Equality operations friend List <elem> operator == (List <elem> L1, List <elem> L2) ; friend List <elem> Equivalent (List <elem> L1, List <elem> L2) ; // Constructor operations for linked list void 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 ) ; C++ Linked List

55 C++ Linked List // I/O functions void 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 () ; Linkedlist* iter ; } ; C++ Linked List

56 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.

57 What defines a component?
Properties, methods, events Design-time and runtime information Integrated help and documentation

58 Properties Properties are “smart fields”
Natural syntax, accessors, inlining public class Button: Control { private string caption; public string Caption { get { return caption; } set { caption = value; Repaint(); Button b = new Button(); b.Caption = "OK"; String s = b.Caption; AP 08/01

59 Indexers Indexers are “smart arrays” Can be overloaded AP 08/01
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[0] = "hello"; Console.WriteLine(listBox[0]); AP 08/01

60 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"); AP 08/01

61 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.

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


Download ppt "Component-based software engineering"

Similar presentations


Ads by Google