28
Page 1 Building Reliable Component-based Systems Chapter 7 - Role-Based Component Engineering Chapter 7 Chapter 7 Role-Based Component Engineering Role-Based Component Engineering

Page 1 Building Reliable Component-based Systems Chapter 7 - Role-Based Component Engineering Chapter 7 Role-Based Component Engineering

Embed Size (px)

Citation preview

Page 1: Page 1 Building Reliable Component-based Systems Chapter 7 - Role-Based Component Engineering Chapter 7 Role-Based Component Engineering

Page 1Building Reliable Component-based Systems Chapter 7 - Role-Based Component Engineering

Chapter 7Chapter 7

Role-Based Component EngineeringRole-Based Component Engineering

Page 2: Page 1 Building Reliable Component-based Systems Chapter 7 - Role-Based Component Engineering Chapter 7 Role-Based Component Engineering

Page 2Building Reliable Component-based Systems Chapter 7 - Role-Based Component Engineering

OverviewOverview

Role-based components

Motivating the use of roles

Role technology

Frameworks and roles

Page 3: Page 1 Building Reliable Component-based Systems Chapter 7 - Role-Based Component Engineering Chapter 7 Role-Based Component Engineering

Page 3Building Reliable Component-based Systems Chapter 7 - Role-Based Component Engineering

Role-based ComponentsRole-based Components

Focusing on the following aspects of object-oriented components:

The interface

The size or granularity

Encapsulation

Composition mechanisms

Page 4: Page 1 Building Reliable Component-based Systems Chapter 7 - Role-Based Component Engineering Chapter 7 Role-Based Component Engineering

Page 4Building Reliable Component-based Systems Chapter 7 - Role-Based Component Engineering

ComponentsComponents

The interface of a component defines the syntax of how to use a component. The semantics of the interface are usually implicit.

Reusability

Plug-ability

Page 5: Page 1 Building Reliable Component-based Systems Chapter 7 - Role-Based Component Engineering Chapter 7 Role-Based Component Engineering

Page 5Building Reliable Component-based Systems Chapter 7 - Role-Based Component Engineering

Concept of RolesConcept of Roles

Components may have several different uses in a system that are dependent on the different roles a component can play in the various component collaborations in the system.

With role-based components is that the public interface is separated into smaller interfaces, which model these different roles.

Page 6: Page 1 Building Reliable Component-based Systems Chapter 7 - Role-Based Component Engineering Chapter 7 Role-Based Component Engineering

Page 6Building Reliable Component-based Systems Chapter 7 - Role-Based Component Engineering

Kemerer and Chidamber’s Kemerer and Chidamber’s Six MetricsSix Metrics

WMC: Weighted Methods per Class

DIT: Depth of Inheritance Tree

NOC: Number Of Children

CBO: Coupling Between Object classes

RFC: Response For a Class

LCOM: Lack of COhesiveness in Methods

Page 7: Page 1 Building Reliable Component-based Systems Chapter 7 - Role-Based Component Engineering Chapter 7 Role-Based Component Engineering

Page 7Building Reliable Component-based Systems Chapter 7 - Role-Based Component Engineering

WMC - WMC - Weighted Methods per ClassWeighted Methods per Class

In terms of classes:

This metric reflects the notion that a complex class has a larger influence on its subclasses than a small class.

In terms of roles:

Roles model only a small part of a class interface.

The amount of WMC of a role is typically less than that of a class.

Components are accessed using the role interfaces.

A smaller part of the interface must be understood than when the same component is addressed using its full interface.

Page 8: Page 1 Building Reliable Component-based Systems Chapter 7 - Role-Based Component Engineering Chapter 7 Role-Based Component Engineering

Page 8Building Reliable Component-based Systems Chapter 7 - Role-Based Component Engineering

DIT - DIT - Depth of Inheritance TreeDepth of Inheritance Tree

In terms of classes:

This metric reflects the notion that a deep inheritance hierarchy constitutes a more complex design.

In terms of roles:

The DIT value will increase since inheritance is the mechanism for imposing roles on a component.

It should be noted however that roles only define the interface, not the implementation.

Thus while the DIT increases, the distribution of implementation throughout the inheritance hierarchy is not affected.

Page 9: Page 1 Building Reliable Component-based Systems Chapter 7 - Role-Based Component Engineering Chapter 7 Role-Based Component Engineering

Page 9Building Reliable Component-based Systems Chapter 7 - Role-Based Component Engineering

NOC - NOC - Number Of ChildrenNumber Of Children

In terms of classes:

This metric reflects the notion that classes with many subclasses are important classes in a design.

In terms of roles:

Since role interfaces are typically located at the top of the hierarchy, the NOC metric will typically be high.

In a conventional class hierarchy, a high NOC for a class expresses that that class is important in the hierarchy.

Similarly, roles with a high NOC are important and have a high cohesiveness value.

Page 10: Page 1 Building Reliable Component-based Systems Chapter 7 - Role-Based Component Engineering Chapter 7 Role-Based Component Engineering

Page 10Building Reliable Component-based Systems Chapter 7 - Role-Based Component Engineering

CBO - CBO - Coupling Between Object classesCoupling Between Object classes

In terms of classes:

This reflects that excessive coupling inhibits reuse and that limiting the number of relations between classes helps to increase their reuse potential.

In terms of roles:

The CBO metric will decrease since implementation dependencies can be avoided by only referring to role interfaces rather than by using classes as types.

Page 11: Page 1 Building Reliable Component-based Systems Chapter 7 - Role-Based Component Engineering Chapter 7 Role-Based Component Engineering

Page 11Building Reliable Component-based Systems Chapter 7 - Role-Based Component Engineering

RFC - RFC - Response For a ClassResponse For a Class

In terms of classes:

This metric measures the number of methods, which can be executed in response to a message.

In terms of roles:

Since roles do not provide any implementation, the RFC value will not increase in implementation classes.

It may even decrease because class inheritance will be necessary to inherit implementation only, interfaces no longer.

Page 12: Page 1 Building Reliable Component-based Systems Chapter 7 - Role-Based Component Engineering Chapter 7 Role-Based Component Engineering

Page 12Building Reliable Component-based Systems Chapter 7 - Role-Based Component Engineering

LCOM - LCOM - Lack of COhesiveness in MethodsLack of COhesiveness in Methods

In terms of classes:

This metric reflects the notion that non-cohesive classes should probably be separated into two classes and that classes with a low degree of cohesiveness are more complex.

In terms of roles:

Roles typically are very cohesive in the sense that the methods for a particular role are closely related and roles will thus, typically, have a lower LCOM value.

Page 13: Page 1 Building Reliable Component-based Systems Chapter 7 - Role-Based Component Engineering Chapter 7 Role-Based Component Engineering

Page 13Building Reliable Component-based Systems Chapter 7 - Role-Based Component Engineering

Transformation ConclusionsTransformation Conclusions

Roles reduce complexity (improvement in CBO, RFC and LCOM metrics).

Roles increase complexity in the upper half of the inheritance hierarchy (Higher DIT and NOC values).

Page 14: Page 1 Building Reliable Component-based Systems Chapter 7 - Role-Based Component Engineering Chapter 7 Role-Based Component Engineering

Page 14Building Reliable Component-based Systems Chapter 7 - Role-Based Component Engineering

Role TechnologyRole Technology

Using roles at the design level

Using roles at the implementation level

Page 15: Page 1 Building Reliable Component-based Systems Chapter 7 - Role-Based Component Engineering Chapter 7 Role-Based Component Engineering

Page 15Building Reliable Component-based Systems Chapter 7 - Role-Based Component Engineering

Using Roles at the Design Level Using Roles at the Design Level

Reenskaug proposes an extension to UML:

General way to express object collaborations

Not too general (class diagrams)

Not too specific (object diagrams)

Uses classifier roles to denote the position an object holds in an object structure.

Page 16: Page 1 Building Reliable Component-based Systems Chapter 7 - Role-Based Component Engineering Chapter 7 Role-Based Component Engineering

Page 16Building Reliable Component-based Systems Chapter 7 - Role-Based Component Engineering

CatalysisCatalysis

Catalysis:

Is a very extensive methodology based on UML, using the concepts of frameworks to model component interactions.

It includes a notion of types and type models.

A type corresponds to a role.

A type model describes typical collaborations between objects of that type.

Page 17: Page 1 Building Reliable Component-based Systems Chapter 7 - Role-Based Component Engineering Chapter 7 Role-Based Component Engineering

Page 17Building Reliable Component-based Systems Chapter 7 - Role-Based Component Engineering

Using Roles at the Implementation Level Using Roles at the Implementation Level

Implementation languages:

Are typically on a lower abstraction level than the design.

Relations between classes in UML are commonly translated to pointers and references when a UML class diagram is implemented in, for example, C++.

With roles, a similar loss of information occurs.

The advantage of expressing roles in this way is that references to other classes can be typed using the interfaces.

Page 18: Page 1 Building Reliable Component-based Systems Chapter 7 - Role-Based Component Engineering Chapter 7 Role-Based Component Engineering

Page 18Building Reliable Component-based Systems Chapter 7 - Role-Based Component Engineering

Mixing ClassesMixing Classes

Interfaces can be simulated by using abstract classes containing only virtual methods without implementation.

Since C++ supports multiple inheritance, these abstract classes can be combined as in Java.

This style of programming is often referred to as using mixing classes.

Page 19: Page 1 Building Reliable Component-based Systems Chapter 7 - Role-Based Component Engineering Chapter 7 Role-Based Component Engineering

Page 19Building Reliable Component-based Systems Chapter 7 - Role-Based Component Engineering

Using Multiple LanguagesUsing Multiple Languages

Roles can also be mapped to IDL interfaces, which makes it possible to use multiple languages (even those not object-oriented) in one system.

Page 20: Page 1 Building Reliable Component-based Systems Chapter 7 - Role-Based Component Engineering Chapter 7 Role-Based Component Engineering

Page 20Building Reliable Component-based Systems Chapter 7 - Role-Based Component Engineering

Using Multiple Languages: ExampleUsing Multiple Languages: Example

According to the API Documentation, the JButton class in the Swing Framework implements the following Java interfaces:

Accessible, ImageObserver, ItemSelectable, MenuContainer, Serializable, SwingConstants.

These interfaces can be seen as roles, which this class can play in various collaborations.

The Serializable interface, for example, makes it possible to write objects of the JButton class to a binary stream.

Page 21: Page 1 Building Reliable Component-based Systems Chapter 7 - Role-Based Component Engineering Chapter 7 Role-Based Component Engineering

Page 21Building Reliable Component-based Systems Chapter 7 - Role-Based Component Engineering

Frameworks and RolesFrameworks and Roles

Using roles together with object-oriented frameworks is useful.

Object- oriented frameworks are partial designs and implementations for applications in a particular domain.

By using a framework, the repeated re-implementation of the same behaviour is avoided and much of the complexity of the interactions between objects can be hidden by the framework.

An example of this is the Hollywood principle ("don't call us, we'll call you") often used in frameworks.

Page 22: Page 1 Building Reliable Component-based Systems Chapter 7 - Role-Based Component Engineering Chapter 7 Role-Based Component Engineering

Page 22Building Reliable Component-based Systems Chapter 7 - Role-Based Component Engineering

Black-box and White-box Frameworks Black-box and White-box Frameworks

Classes

Components

Abstract classes

Interfaces

Design documents

Are a part of

Inherit

Implement

Partially implement

Reflect

Page 23: Page 1 Building Reliable Component-based Systems Chapter 7 - Role-Based Component Engineering Chapter 7 Role-Based Component Engineering

Page 23Building Reliable Component-based Systems Chapter 7 - Role-Based Component Engineering

Framework ElementsFramework Elements

Design documents

Role Interfaces

Abstract classes

Components

Classes

Page 24: Page 1 Building Reliable Component-based Systems Chapter 7 - Role-Based Component Engineering Chapter 7 Role-Based Component Engineering

Page 24Building Reliable Component-based Systems Chapter 7 - Role-Based Component Engineering

A Model for Frameworks A Model for Frameworks

In this section we will do so by specifying the general structure of a framework and comparing this with some existing ideas on this topic.

Composition of framework control

Composition with legacy code

Framework gap

Overlap of framework functionality

Page 25: Page 1 Building Reliable Component-based Systems Chapter 7 - Role-Based Component Engineering Chapter 7 Role-Based Component Engineering

Page 25Building Reliable Component-based Systems Chapter 7 - Role-Based Component Engineering

Dealing With Coupling Dealing With Coupling

More coupling between components means higher maintenance costs (McCabe’s cyclomatic complexity).

Page 26: Page 1 Building Reliable Component-based Systems Chapter 7 - Role-Based Component Engineering Chapter 7 Role-Based Component Engineering

Page 26Building Reliable Component-based Systems Chapter 7 - Role-Based Component Engineering

Strategies for Dealing With CouplingStrategies for Dealing With Coupling

That which they have in common is that for component X to use component Y, X will need a reference to Y.

Y is created by X and then discarded.

Y is a property of X.

Y is passed to X as a parameter of some method.

Y is retrieved by requesting it from a third object.

Page 27: Page 1 Building Reliable Component-based Systems Chapter 7 - Role-Based Component Engineering Chapter 7 Role-Based Component Engineering

Page 27Building Reliable Component-based Systems Chapter 7 - Role-Based Component Engineering

Dependencies Between ComponentsDependencies Between Components

Regardless of how the reference is obtained, there are two types of dependencies between components:

Implementation dependencies: The references used in the relations between components are typed using concrete classes or abstract classes.

Interface dependencies: The references used in the relations between components are typed using only interfaces.

Page 28: Page 1 Building Reliable Component-based Systems Chapter 7 - Role-Based Component Engineering Chapter 7 Role-Based Component Engineering

Page 28Building Reliable Component-based Systems Chapter 7 - Role-Based Component Engineering

Dependency ConsiderationsDependency Considerations

Disadvantage of implementation dependencies

It is more difficult to replace the objects to which the component delegates.

When interface dependencies are used, the object can be replaced with any other object implementing the same interface.

Interface dependencies are thus more flexible and should always be preferred to implementation dependencies.

In the model presented in this section, all components implement interfaces from role models making the use implementation dependencies in the implementation of these components unnecessary.