scl

32
Scl : a Simple, Uniform and Operational Language for Component-Oriented Programming in Smalltalk Luc Fabresse Christophe Dony Marianne Huchard LIRMM Universit´ e Montpellier 2 France September 3, 2006 Fabresse, Dony, Huchard (Lirmm/UM2) Component-Oriented Programming ESUG 2006 1 / 32

Upload: esug

Post on 16-Jun-2015

382 views

Category:

Technology


0 download

DESCRIPTION

Scl : a Simple, Uniform and Operational Language for Component-Oriented Programming in Smalltalk. Luc Fabresse, Christophe Dony, Marianne Huchard. ESUG 2006, Prague

TRANSCRIPT

Page 1: SCL

Scl :a Simple, Uniform and Operational Language

for Component-Oriented Programmingin Smalltalk

Luc Fabresse Christophe Dony Marianne Huchard

LIRMMUniversite Montpellier 2

France

September 3, 2006

Fabresse, Dony, Huchard (Lirmm/UM2) Component-Oriented Programming ESUG 2006 1 / 32

Page 2: SCL

Outline

1 Context

2 A Short Overview of Scl

3 The Connection Mechanism

4 AOP Support Using Connectors

5 Publish/Subscribe Support Using Properties

6 Conclusions

Fabresse, Dony, Huchard (Lirmm/UM2) Component-Oriented Programming ESUG 2006 2 / 32

Page 3: SCL

Outline

1 Context

2 A Short Overview of Scl

3 The Connection Mechanism

4 AOP Support Using Connectors

5 Publish/Subscribe Support Using Properties

6 Conclusions

Fabresse, Dony, Huchard (Lirmm/UM2) Component-Oriented Programming ESUG 2006 3 / 32

Page 4: SCL

The High-Level View of CBSD

Component

Component LibraryApplication

Programmer Architect

creates

stored usedD

A

D

creates

B

A C

D

Fabresse, Dony, Huchard (Lirmm/UM2) Component-Oriented Programming ESUG 2006 4 / 32

Page 5: SCL

Current Issues in CBSD

Fundamental Questions

What is a component? [Szyperski, 1996]

Component structure?

Component composition?

Practical Needs

Models

Languages

Tools

Fabresse, Dony, Huchard (Lirmm/UM2) Component-Oriented Programming ESUG 2006 5 / 32

Page 6: SCL

Outline

1 Context

2 A Short Overview of Scl

3 The Connection Mechanism

4 AOP Support Using Connectors

5 Publish/Subscribe Support Using Properties

6 Conclusions

Fabresse, Dony, Huchard (Lirmm/UM2) Component-Oriented Programming ESUG 2006 6 / 32

Page 7: SCL

Simple Component Language (Scl)

What is Scl?

A component-oriented programming language

Main purposes of Scl

Simple, few and only fundamental entities

Uniform, not an asymmetric extension of an object-oriented language

Enables unanticipated composition of independently developedcomponents

Synthesis of existing component-oriented languages ideas

Operationnal, implemented in Smalltalk

Extensible to experiment new ideas

Fabresse, Dony, Huchard (Lirmm/UM2) Component-Oriented Programming ESUG 2006 7 / 32

Page 8: SCL

Basic Entities (1/2)

Component

Black box

Ports decribed by interfaces

Provides and requires services

Port

Interaction point

Plug

Fabresse, Dony, Huchard (Lirmm/UM2) Component-Oriented Programming ESUG 2006 8 / 32

Page 9: SCL

Basic Entities (1/2)

Service

Functionnality

Like a method or a set of methods

Interface

Describes the valid uses of a port

Service signatures sets, protocols, contracts, ...

Fabresse, Dony, Huchard (Lirmm/UM2) Component-Oriented Programming ESUG 2006 9 / 32

Page 10: SCL

Example : a chatclient component

Chatting

ChatClient

Interface

Orientation

Port

Caption:

Networking

connect:disconnectsendData:receiveData

join:leavesend:

Fabresse, Dony, Huchard (Lirmm/UM2) Component-Oriented Programming ESUG 2006 10 / 32

Page 11: SCL

1 Context

2 A Short Overview of Scl

3 The Connection Mechanism

4 AOP Support Using Connectors

5 Publish/Subscribe Support Using Properties

6 Conclusions

Fabresse, Dony, Huchard (Lirmm/UM2) Component-Oriented Programming ESUG 2006 11 / 32

Page 12: SCL

The Connector entity

Connector = Reification of Connection

Better separation

Non-fixed connection semantics

Solves adaptation problems

Possible creation of a reusable library of connectors

The General Connector Structure

Sources, a set of ports

Targets, a set of ports

Glue code

Fabresse, Dony, Huchard (Lirmm/UM2) Component-Oriented Programming ESUG 2006 12 / 32

Page 13: SCL

A Graphical View of a Connector

<<SclConnector>>

Required ProvidedPorts

glue code

Sources Targets

Ports

Fabresse, Dony, Huchard (Lirmm/UM2) Component-Oriented Programming ESUG 2006 13 / 32

Page 14: SCL

Example: Connection of two matching components

<<SclBinaryConnector>>Chatting

Source

ConnectionManager

Target

ChatClient

Networking Networking

SclBinaryConnector new

source: ( chatClient port: #Networking )

target: ( connectionManager port: #Networking ) ;

connect

Similar to:

bindings in Fractal

connect primitive in Archjava

Fabresse, Dony, Huchard (Lirmm/UM2) Component-Oriented Programming ESUG 2006 14 / 32

Page 15: SCL

Example: Connection of two Components with Adaptation

ChatClient

Networking Networking<<SclBinaryConnector>>

Code glue

Chatting

Source

ConnectionManager

Target

connect:disconnectsendData:

receiveData

closeConnectionopenConnectionTo:

send:receive:

Fabresse, Dony, Huchard (Lirmm/UM2) Component-Oriented Programming ESUG 2006 15 / 32

Page 16: SCL

Example: Connection of two Components with Adaptation

receivesendData:

closeConnectionopenConnectionTo:

Target

send:disconnectconnect:

ChatClient

Networking Networking<<SclBinaryConnector>>

Code glue

Chatting

Source

ConnectionManager

receiveData:

SclBinaryConnector new

source: ( chatClient port: #Networking )

target: ( connectionManager port: #Networking )

glue: [ :source :target :message |

(message selector = #connect:) ifTrue: [

^ target openConnectionTo: (message arguments)

]

... "some more stuff"

] ; connect.

Fabresse, Dony, Huchard (Lirmm/UM2) Component-Oriented Programming ESUG 2006 16 / 32

Page 17: SCL

1 Context

2 A Short Overview of Scl

3 The Connection Mechanism

4 AOP Support Using Connectors

5 Publish/Subscribe Support Using Properties

6 Conclusions

Fabresse, Dony, Huchard (Lirmm/UM2) Component-Oriented Programming ESUG 2006 17 / 32

Page 18: SCL

Mixing AOP and Component Appoaches

Why?

Encapsulate the scaterred code of specific concerns (Log, Transaction,...)

How?

Asymmetric approaches

Symmetric approaches

Fabresse, Dony, Huchard (Lirmm/UM2) Component-Oriented Programming ESUG 2006 18 / 32

Page 19: SCL

Limited AOP support in Scl

Joint Points on Ports

before/after/around service invocation

before/after/around connection/disconnection

Special Connectors

Source ports are coupled with a keyword (beforeServiceInvocation, ...)

Weaving

Regular connection/disconnection mechanism

Fabresse, Dony, Huchard (Lirmm/UM2) Component-Oriented Programming ESUG 2006 19 / 32

Page 20: SCL

Example: A Logger component

LoggerChatClient

Networking Chatting

log:

<<beforeSI>>

Logging

glue code

<<SclFlowConnector>>

SclFlowBinaryConnector new

source: ( (chatClient port: #Chatting) beforeServiceInvocation )

target: ( logger port: #Logging )

glue: [ :source :target :message |

target log: (message selector asString)

] ; connect.

Fabresse, Dony, Huchard (Lirmm/UM2) Component-Oriented Programming ESUG 2006 20 / 32

Page 21: SCL

1 Context

2 A Short Overview of Scl

3 The Connection Mechanism

4 AOP Support Using Connectors

5 Publish/Subscribe Support Using Properties

6 Conclusions

Fabresse, Dony, Huchard (Lirmm/UM2) Component-Oriented Programming ESUG 2006 21 / 32

Page 22: SCL

Motivating Example (1/2)

How to connect a chatclient component with a GUI component ?

Chatting

Accessing

chatTextchatText:

displayTextdisplayText:

ChatClient

Networking

TextArea

Accessing

Fabresse, Dony, Huchard (Lirmm/UM2) Component-Oriented Programming ESUG 2006 22 / 32

Page 23: SCL

Motivating Example (2/2)

How to connect a chatclient component with a GUI component ?

ChatClient

Networking

Notifying

TextArea

Accessing

chatTextChanged:

Chatting

Accessing

chatTextchatText:

displayTextdisplayText:

Fabresse, Dony, Huchard (Lirmm/UM2) Component-Oriented Programming ESUG 2006 23 / 32

Page 24: SCL

The limitations with components

Publisher side limitations

Event signaling (Archjava, CCM, ...)

Subscribers management (Javabeans, ...)

Subscriber side limitations

Receivable events (CCM, ...)

Subscriber reaction

Goal

Extract the application dependent code from components

Fabresse, Dony, Huchard (Lirmm/UM2) Component-Oriented Programming ESUG 2006 24 / 32

Page 25: SCL

The Scl Solution Based on Properties

Property

External state of a component (Javabeans)

Automatically notifies its value changes if needed

Only declared by the component programmer

Property Structure:

A name

An access port provides getter and setter services

A notification port to invoke notifying services

Notifying services

Notify Before Change, nbc:value:oldValue:

Notify After Change, nac:value:oldValue:

...

Fabresse, Dony, Huchard (Lirmm/UM2) Component-Oriented Programming ESUG 2006 25 / 32

Page 26: SCL

Example: The chat client component with a ChatTextproperty

a connected component is able to do (nothing, prevent themodification or change the property value). An example ofconnection using properties is depicted on Figure 6 and thecorresponding SCL code is shown on Figure 7.

displayText:

chatText:

chatText

ChatClient

ChatClientGui

DisplayingChatText

Networking

SendingChatting

nac:value:oldValue:

nbc:value:oldValue:

Figure 6. Connect components using proper-ties changes notifications

c l i e n t := CHATCLIENT new.c l i e n t G u i := CHATCLIENTGUI new.

SCLBINARYNACCONNECTOR newsource: ( c l i e n t notifyPortOf: # C h a tT e x t )target: ( c l i e n t G u i port: # D i s p l a y i n g )glue: [ :source :g u i :message |

g u i displayText: (message arguments second).]; connect.

Figure 7. Connecting two components basedon a property changes notifications

In this example, each time the chatText prop-erty of the CHATCLIENT is changed, this results inchanging the displayed text on the CHATCLIENTGUI dueto the SCLBINARYNACCONNECTOR that only considersnac:value:oldValue: invocations on the source port.Special connectors like SCLBINARYNACCONNECTOR easeconnection writing. Moreover, a software architect is ableto build reusable connectors that can be included in a li-brary of generic connectors. Actually, SCL provides dif-ferent kinds of connectors like SCLBINARYNACCONNEC-TOR, SCLBINARYNBCCONNECTOR, PROPERTYBINDERCON-NECTOR ensuring that the value of the target property is al-ways synchronized with the value of the source property.

Figure 8 shows the complete code of the CHATCLIENT.Figure 9 shows the complete connection code necessary tobuild the application. Figure 10 shows a simulation codeand Figure 11 shows the screenshot of this simulation1 exe-cution.

1The whole code is available at http://www.lirmm.fr/˜fabresse/scl

SCLCOMPONENTBUILDER create: # C h a t C l i e n tproperties: ’ c h a t T e x t nickName ’.outPorts: ’ Ne twork ing ’ inPorts: ’ C h a t t i n g ’.

CHATCLIENT>>init ” p r e s e n t e d i n F ig u r e 3”

CHATCLIENT>>primitivechatText” i n t e r n a l component a c c e s s o r d e f i n e d by t h eprogrammer and used by t h e g e n e r a t e d c h a t T e x tp r o p e r t y a c c e s s o r ”chatText ifNil: [ chatText := ’ ’ ].ˆchatText

CHATCLIENT>>primitivechatText: newVchatText := newV

CHATCLIENT>>primitivenickNamenickName ifNil: [ nickName := ’ anonymous ’ ].ˆnickName

CHATCLIENT>>primitivenickName: nnickName := n

CHATCLIENT>>leave(self port: # Ne twork ing) disconnect.

CHATCLIENT>>send: aMessage(self port: # Ne twork ing)send: ( ’< ’, self nickName, ’> ’, aMessage)

CHATCLIENT>>receive: aMessage(self accessPortOf: # c h a t T e x t) chatText:(self chatText, String crlf, aMessage).

Figure 8. The CHATCLIENT SCL code

Properties are a new feature that helps component pro-gramming by providing a higher abstraction to componentprogrammers and software architects. Figure 12 illustratesthis fact because a new functionality is added to our chatclient with only one ”state connection”.

This connection allows our chat client application toautomatically send the current title played by our musicplayer to other chat users. In other words, each timethe CurrentTitle property of the component MUSIC-PLAYER is modified, a message is sent to chat users usingthe send: service of the CHATCLIENT component throughits Chatting port.

5 Related Work

Our approach is similar to Javabeans componentmodel [16]. A Javabeans programmer declares propertiesthrough syntactic name conventions like get and set andwrites the event signaling code to enable connection basedon Javabeans properties event signals. The Javabeans modeldistinguishes different kinds of properties depending on sig-nals like bound properties that notify connected Javabeans

4

nbc:value:oldValue:

chatText:

nac:value:oldValue:

ChatClient

ChattingChatText

Networking

chatText

Fabresse, Dony, Huchard (Lirmm/UM2) Component-Oriented Programming ESUG 2006 26 / 32

Page 27: SCL

States changes connections

Standard connections

Based on connectors (ports + glue code)

Source ports are notifying ports of properties

Features

Uniformity

Extensibility

Fabresse, Dony, Huchard (Lirmm/UM2) Component-Oriented Programming ESUG 2006 27 / 32

Page 28: SCL

Example: The whole chat client application

P

P

ChatClient

Networking

Chatting

ChatText

NickName

ChatClientGui

Networking

NetworkManager

<<SclBinaryNacConnector>>

Displaying

Sending

<<SclBinaryNacConnector>>

SclBinaryNacConnector new

source: ( chatClient notifyPortOf: #ChatText )

target: ( chatClientGui port: #Displaying )

glue: [ :source :gui :anInvocation |

gui displayText: anInvocation arguments second

] ; connect.

Fabresse, Dony, Huchard (Lirmm/UM2) Component-Oriented Programming ESUG 2006 28 / 32

Page 29: SCL

Implementation of Scl

Advantages of Smalltalk

Prototyping is easier and faster than in statically typed languages

The meta-level enables message interceptions, addition of new entities(Component, Connector, ...), ...

Block can be used for representing glue code

A step to investigate what could be a dynamic component orientedlanguage

Difficulty(ies) with Smalltalk

Encapsulation

Fabresse, Dony, Huchard (Lirmm/UM2) Component-Oriented Programming ESUG 2006 29 / 32

Page 30: SCL

Outline

1 Context

2 A Short Overview of Scl

3 The Connection Mechanism

4 AOP Support Using Connectors

5 Publish/Subscribe Support Using Properties

6 Conclusions

Fabresse, Dony, Huchard (Lirmm/UM2) Component-Oriented Programming ESUG 2006 30 / 32

Page 31: SCL

Conclusions

Scl

A component-oriented language

Only one entity of reuse: Component

Component Composition

Connections based on Connectors

AOP support using Connectors

Component Properties

Prototyped in Smalltalk

Current Work

Larger case studies

Investigate dynamicity

Improve the prototype

Tools

Fabresse, Dony, Huchard (Lirmm/UM2) Component-Oriented Programming ESUG 2006 31 / 32

Page 32: SCL

Thanks...

Questions?Suggestions?Comments?

Fabresse, Dony, Huchard (Lirmm/UM2) Component-Oriented Programming ESUG 2006 32 / 32