Download Java Layers Language Presentation

Survey
yes no Was this document useful for you?
   Thank you for your participation!

* Your assessment is very important for improving the work of artificial intelligence, which forms the content of this project

Document related concepts
no text concepts found
Transcript
Java Layers
Language Support for Stepwise
Refinement
Rich Cardone, IBM Research & UT at Austin
Calvin Lin, University of Texas at Austin
Problem


Software development and maintenance is expensive

Difficult

Takes a long time
Assemble applications from off-the-shelf components

Mix and match features to create applications

Plug and unplug components to change applications
12/7/00
Java Layers/RC,CL
2
Reuse is Key

Separation of concerns


One application feature per component
Flexible composition
12/7/00
Java Layers/RC,CL
3
Presentation Overview


Part I – Motivation

Mixins

Stepwise Refinement

Drawbacks of Mixins
Part II – Java Layers
12/7/00

Java Layers Overview

Two Language Features
Java Layers/RC,CL
4
An OO Problem
Car
Box
House
Lockable
Car
Lockable
Box
Lockable
House
lock(), unlock()
Problem: Lockable code replicated 3 times
12/7/00
Java Layers/RC,CL
5
An OO Solution

Use same lockable code for all 3 classes


Encapsulate lockable code in a class
Subtype Car, Box, House with new class
Mixin Class
class Lockable<T> extends T {
lock(){…}
unlock(){…}
}
[Bracha90]
12/7/00
Java Layers/RC,CL
6
Mixed-In Classes
<T>
Car
Box
House
Lockable<T>
Lockable<Car>
Lockable<Box>
Lockable<House>
Lockable code reused 3 times
12/7/00
Java Layers/RC,CL
7
Mixins

Types with parameterized supertypes

Depend on type parameters

More precisely: Parametric Polymorphism

An OO mechanism for code reuse

Apply same code to unrelated classes

Work with single inheritance
12/7/00
Java Layers/RC,CL
8
Mixins & Software Components

Question


If so, then mixins must support:



Can we use mixins to build applications out of
reusable components?
Separation of concerns
Flexible composition
Let’s look at an example application
12/7/00
Java Layers/RC,CL
9
Example: Music Server

Variation can occur on many axes:

Client interface
{getSong, putSong, eraseCopyright, hideBritney, …}

Server execution strategy
{single threaded, thread-spawning, thread pool, …}
12/7/00

Transport type

Fault tolerance

Server discovery

…
Java Layers/RC,CL
10
Music Application Instances
Simple
NoBritney
Base
Base
Base
GetSong
GetSong
EraseCopyright
PutSong
PutSong
GetSong
HideBritney
ThreadSpawn
leaf-types
12/7/00
Java Layers/RC,CL
Thief
…
11
Application Assembly is Easy
class Simple extends
PutSong<GetSong<Base>> {…}
class NoBritney extends
HideBritney<PutSong<GetSong<Base>>> {…}
class Thief extends
ThreadSpawn<GetSong<EraseCopyright<
Base>>> {…}
12/7/00
Java Layers/RC,CL
12
Base Class
class Base {
static public class Client {…}
static public class Server {
void dispatchLoop(){for(;;) dispatch(readRequest());}
void dispatch(Req req){errorUnknownReq(req);}
…
}
}
12/7/00
Java Layers/RC,CL
13
GetSong Mixin
constraint
nested mixins
class GetSong<T extends Base> extends T {
static public class Client extends T.Client {
void getSong(…){…} }
static public class Server extends T.Server {
void dispatch(Req req){
if (req.name.equals(“getSong”)) processGetSong(req);
else super.dispatch(req);
}
…
}
}
12/7/00
Java Layers/RC,CL
14
Other Mixins
class EraseCopyright<T extends Base> extends T {
static public class Client extends T.Client {
void eraseCopyright(…){…}
} …
}
class ThreadSpawn<T extends Base> extends T {
static public class Server extends T.Server {
void dispatchLoop(){…}
} …
}
12/7/00
Java Layers/RC,CL
15
Stepwise Program Refinement
class Thief extends
ThreadSpawn<GetSong<EraseCopyright<Base>>> {…}
Client
Server
Layers
Base
EraseCopyright
GetSong
ThreadSpawn
[Batory92]
12/7/00
Java Layers/RC,CL
16
Drawbacks of Mixins

Superclass initialization

Runtime efficiency

Leaf-type references

Composition validation
12/7/00

Semantic validity

Syntactic correctness
Java Layers/RC,CL
17
Recap

Software components imply reuse

Mixins reuse OO code

Mixins build applications incrementally


Stepwise program refinement

Nested types encapsulate features

Feature mixing and matching
Mixins have usability & efficiency drawbacks
12/7/00
Java Layers/RC,CL
18
Part II – Java Layers

Java Layers Overview

Two JL Language Features

Status

Conclusion
12/7/00
Java Layers/RC,CL
19
Goal of Java Layers

Increase software reuse to reduce
development and maintenance costs

Use layered, stepwise program refinement

Encapsulate features in mixins classes

Compose features through type instantiation
12/7/00
Java Layers/RC,CL
20
JL’s Foundation

Java + Constrained Parametric Polymorphism (CPP)

There are several proposals for adding CPP to Java
[Agesen97, Bokowski98, Bracha98, Cartwright98, Myers97, Solorzano98]

JL is a heterogeneous implementation of CPP

Conventional syntax and semantics

Parametric classes and interfaces

Mixins
12/7/00
Java Layers/RC,CL
21
The JL Language
JL is a parametric Java plus 4 features:

Deep conformance

Static virtual typing

Semantic checking

Constructor propagation
All language extensions are designed to support
stepwise refinement
12/7/00
Java Layers/RC,CL
22
JL Compiler Support

Class hierarchy optimization

Remove design-time layering from runtime code

Inline calls to superclass methods w/same signature

Collapse class hierarchy into a single class
12/7/00
Java Layers/RC,CL
23
The Need for Deep Conformance
Question:
class Parent {
class Inner {…}
}
Does Child contain a nested
class named Inner?
class Child
extends Parent {…}

Java supports shallow type checking


Answer: Maybe
Interfaces and classes
JL adds support for deep type checking

12/7/00
Supertypes are checked for required nested types
Java Layers/RC,CL
24
Deep Conformance

Deep Conformance supports stepwise refinement

Enforces structural conformance at all nesting depths

Subtypes can safely refer to nested types in their supertypes

Feature composition is enhanced by added type precision
12/7/00
Java Layers/RC,CL
25
Deep Conformance Example
class HideBritney<T extends Base deeply> extends deeply T {
static public class Client extends T.Client {…}
static public class Server extends T.Server {…} }

Type parameter T binds to classes that:




Extend Base
Contain a nested Client class that extends Base.Client
Contain a nested Server class that extends Base.Server
HideBritney contains all the public nested types of T

12/7/00
Compiler generates missing nested types if necessary
Java Layers/RC,CL
26
Deep Conformance Syntax


Deeply modifier for implements and extends clauses

Different meaning in constraint and inheritance clauses

Operates on public nested types by default
Propagate modifier for non-public nested types


Enables selective deep type checking
Use in parameterized and non-parameterized types
12/7/00
Java Layers/RC,CL
27
A Use of Virtual Types
class Node {Node next;}
class Node
{virtual Node; Node next;}
class DoubleNode
extends Node
{DoubleNode prev;}
class DoubleNode extends Node
{typedef Node as DoubleNode;
DoubleNode prev;}

In DoubleNode:

In DoubleNode:

next is type Node

next is type DoubleNode

prev is type DoubleNode

prev is type DoubleNode
[Thorup97]
12/7/00
Java Layers/RC,CL
28
Virtual Types


The automatic adaptation of types through inheritance.

Virtual types change through subtyping

A child class can change the type of its parent
Benefits of Virtual Typing

Greater type precision

Better type checking

Less manual typecasting

Genericity (Beta)
12/7/00
Java Layers/RC,CL
29
JL’s This Virtual Type

This pseudo-type is like the “type of this.”

Static binding


Used in parametric types only

Bound at instantiation time
Enhances JL’s expressiveness

12/7/00
Allows the instantiated leaf-type to be expressed
within the mixins being composed to define that
leaf-type.
Java Layers/RC,CL
30
This Example
Base
class ClientFactory<T extends Base deeply>
extends T deeply {
GetSong
ClientFactory
PutSong
static public class Client
extends T.Client
{
static Client
This clientFactory()
clientFactory()
{return new This();}
Client();}
} … }
leaf-type
12/7/00
Java Layers/RC,CL
31
Work Completed

Implemented JL prototype

Compared JL to OO Frameworks

Reengineered Schmidt’s ACE

ICSE 2001 paper
12/7/00
Java Layers/RC,CL
32
Future Work

Develop new JL compiler


Implement language described here
Build a family of related applications

12/7/00
Compare JL and OO approaches
Java Layers/RC,CL
33
Related Work

GenVoca – Batory92-00, Smaragdakis98-99

Parametric Polymorphism – Agesen97, Bokowski98,
Bracha90, Bracha98, Cartwright98, Myers97, Solorzano98

Virtual Types – Bruce97-98, Madsen89, Thorup97,
Thorup99, Torgerson98

Semantic Checking – Batory95, Perry89-93

Programming Paradigms – Danforth98, Gamma94,
Harrison93, Johnson91, Kiczales97, Schmidt98, Tarr99
12/7/00
Java Layers/RC,CL
34
Conclusion


JL extends Java to improve reusability

Promotes stepwise program refinement

Assembles applications from reusable parts

Builds on parametric polymorphism

Adds a small number of language features
Is this approach practical for application programming?
12/7/00
Java Layers/RC,CL
35
THE END
Think Layers
12/7/00
Java Layers/RC,CL
36