Home

 

Getting Started with Elisa

Using EDS

Demo's

Tutorials

 

Language Description

1. Lexical Elements
2. Basic Data Types and Expressions
3. Definitions
4. Streams
5. Backtracking
6. Statements and Special Expressions
7. Arrays
8. Lists
9. Descriptors
10. Components
11. Collections
12. Generic Components
13. Terms
14. Categories
15. Types 

16. Built-in Definitions
17. Higher-order Definitions

18. External Interfaces

Index

Data Structures

1. Sequences
2. Examples involving Lists
3. Trees
4. Graphs
5. Searching State Spaces
6. Language Processing
7. Knowledge Representations          

 

Metaprogramming

1. Introduction
2. What are Domain Definitions?

3.  Sorts of Domain Definitions

4.  Manipulations of Domain Definitions

5.  Translating Domain Definitions

6.  Dialogue Sessions

7.  Example of Concentric Circles

8.  Example of Domain Substitution applied to Concentric Circles

9.  Example of an Order Processing Application

10.Example of an Airport Information System

11.Example of a Rental Boat Business

12.Benefits of Domain Definitions

   

Back Home Up Next


STATE

1 Purpose

2 Problem Description

3 Domain Definitions

4 Elisa Components

1  Purpose

Allow an object to alter its behavior when its internal state changes. The object will appear to change its class. Also known as Objects for States.

2  Problem Description

Consider a class TCPConnection that represents a network connection. A TCPConnection object can be in one of several different states: Established, Listening, Closed. When a TCPConnection object receives requests from other objects, it responds differently depending on its current state. For example, the effect of an Open request depends on whether the connection is in its Closed state or its Established state. The State pattern describes how TCPConnection can exhibit different behavior in each state.

The key idea in this pattern is to introduce an abstract class called TCPState to represent the states of the network connection. The TCPState class declares an interface common to all classes that represent different operational states. Subclasses of TCPState implement state-specific behavior. For example, the classes TCPEstablished and TCPClosed implement behavior particular to the Established and Closed states of TCPConnection.

The class TCPConnection maintains a state object (an instance of a subclass of TCPState) that represents the current state of the TCP connection. The class TCPConnection delegates all state-specific requests to this state object. TCPConnection uses its TCPState subclass instance to perform operations particular to the state of the connection.

Whenever the connection changes state, the TCPConnection object changes the state object it uses. When the connection goes from established to closed, for example, TCPConnection will replace its TCPEstablished instance with a TCPClosed instance.

3  Domain Definitions

We will transform the top-level  relations into a set of corresponding domain definitions:

TCPState =  TCPEstablished  | TCPListen | TCPClosed

TCPConnection =  TCPState 

The next step is to translate the domain definitions into a number of Elisa components. In addition, we will use skeletons of definitions as shown in the preceding domain relationships

4  Elisa components 

Based on the domain definitions a set of related components are derived. The first component implements  a skeleton of the  TCPState = TCPEstablished  | TCPListen | TCPClosed domain.

component TCPStates;
type TCPState = category(TCPEstablished,TCPListen,TCPClosed);

     Open(TCPState) -> nothing;

     Close(TCPState) -> nothing;

     Acknowledge(TCPState) -> nothing;

      . . .
begin

            <<implementations of >>

     Open(TCPEstablished:tcpEstablished) = Open(tcpEstablished);

     Open(TCPListen:tcpListen)           = Open(tcpListen);

     Open(TCPClosed:tcpClosed)           = Open(tcpClosed);

 

     Close(TCPEstablished:tcpEstablished) = Close(tcpEstablished);

     Close(TCPListen:tcpListen)           = Close(tcpListen);

     Close(TCPClosed:tcpClosed)           = Close(tcpClosed);

 

     Acknowledge(TCPEstablished:tcpEstablished) = Acknowledge(tcpEstablished);

     Acknowledge(TCPListen:tcpListen)           = Acknowledge(tcpListen);

     Acknowledge(TCPClosed:tcpClosed)           = Acknowledge(tcpClosed);

 

          . . .

end component TCPStates;

 


The following component is a skeleton example of a TCPEstablished component:

 

component TCPEstablisheds;
type TCPEstablished;

     CreateTCPEstablished (TCPState) -> TCPEstablished;

     TCPState(TCPEstablished) -> TCPState; 

     Open(TCPEstablished) -> nothing;

     Close(TCPEstablished) -> nothing;

     Acknowledge(TCPEstablished) -> nothing;

      . . .
begin

            <<implementations of >>

     CreateTCPEstablished(tCPState) = TCPEstablished:[..tCPState..]; 

     TCPState(tCPEstablished) = tCPEstablished.tCPState; 

     Open(tCPEstablished) = ...;

     Close(tCPEstablished) = ...;

     Acknowledge(tCPEstablished) = ...;

          . . .

end component TCPEstablisheds;

 

 

The following component is a skeleton example of a TCPListen component:

 

component TCPListens;
type TCPListen;

     CreateTCPListen (TCPState) -> TCPListen;

     TCPState(TCPListen) -> TCPState; 

     Open(TCPListen) -> nothing;

     Close(TCPListen) -> nothing;

     Acknowledge(TCPListen) -> nothing;

      . . .
begin

            <<implementations of >>

     CreateTCPListen(tCPState ) = TCPListen:[..tCPState.. ]; 

     TCPState(tCPListen) = tCPListen.tCPState; 

     Open(tCPListen) = ...;

     Close(tCPListen) = ...;

     Acknowledge(tCPListen) = ...;

          . . .

end component TCPListens;


 

The following component is a skeleton example of a TCPClosed

 

component TCPCloseds;
type TCPClosed;

     CreateTCPClosed (TCPState) -> TCPClosed;

     TCPState(TCPClosed) -> TCPState; 

     Open(TCPClosed) -> nothing;

     Close(TCPClosed) -> nothing;

     Acknowledge(TCPClosed) -> nothing;

      . . .
begin

            <<implementations of >>

     CreateTCPClosed(tCPState ) = TCPClosed:[..tCPState.. ]; 

     TCPState(tCPClosed) = tCPClosed.tCPState; 

     Open(tCPClosed) = ...;

     Close(tCPClosed) = ...;

     Acknowledge(tCPClosed) = ...;

          . . .

end component TCPCloseds;


 

The following component is a skeleton example of a TCPConnection

 

component TCPConnections;
type TCPConnection;

     CreateTCPConnection () -> TCPConnection;

     Open(TCPConnection) -> nothing;

     Close(TCPConnection) -> nothing;

     Acknowledge(TCPConnection) -> nothing;

      . . .
begin

            <<implementations of >>

     CreateTCPConnection( ) = TCPConnection:[... ]; 

     Open(TCPConnection) = ...;

     Close(TCPConnection) = ...;

     Acknowledge(TCPConnection) = ...;

          . . .

end component TCPConnections;

 

 

 

Back Home Up Next

  Part 5: Design Patterns   State

            
Introduction

Home | Highlights of Elisa | Integrating Different Paradigms | Getting Started with Elisa | Demo's  | What is Domain Orientation | Bibliography | Copyright | News | Contact | Contents

Language Description:

Lexical Elements | Basic Data Types and Expressions | Definitions | Streams | Backtracking | Statements and Special Expressions | Arrays | Lists | Descriptors | Components | Collections | Generic Components | Terms | Categories | Types | Built-in Definitions | Higher-order Definitions | External Interfaces | Index 

Data Structures: Sequences | Examples involving Lists | Trees | Graphs | Searching State Spaces | Language Processing | Knowledge Representations
Domain Modeling:

Domain Modeling | Concepts | Domain Definitions | Domain Operations | Domain Implementations | Systems | Case study: an Order processing system | Case study: an Airport Support system | Domain Orientation versus Object Orientation

Design Patterns:

Introduction | Abstract Factory | Builder | Factory Method | Prototype | Singleton | Adapter | Bridge | Composite | Decorator | Facade | Flyweight | Proxy | Chain of Responsibility | Command | Interpreter | Iterator | Mediator | Memento | Observer | State | Strategy | Template Method | Visitor 

 

click tracking

This page was last modified on 04-12-2012 13:09:39   

free hit counter