
95452f3b25e59ba381886ee2ef40120f.ppt
- Количество слайдов: 36
Java Layers Language Support for Stepwise Refinement Rich Cardone, IBM Research & UT at Austin Calvin Lin, University of Texas at Austin 12/7/00 Java Layers/RC, CL
Problem n Software development and maintenance is expensive n n n Difficult Takes a long time Assemble applications from off-the-shelf components n Mix and match features to create applications n Plug and unplug components to change applications 12/7/00 Java Layers/RC, CL 2
Reuse is Key n Separation of concerns n n One application feature per component Flexible composition 12/7/00 Java Layers/RC, CL 3
Presentation Overview n Part I – Motivation n n Stepwise Refinement n n Mixins Drawbacks of Mixins Part II – Java Layers n n 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 n Use same lockable code for all 3 classes n n Encapsulate lockable code in a class Subtype Car, Box, House with new class Mixin Class class Lockable
Mixed-In Classes
Mixins n Types with parameterized supertypes n Depend on type parameters n More precisely: Parametric Polymorphism n An OO mechanism for code reuse n Apply same code to unrelated classes n Work with single inheritance 12/7/00 Java Layers/RC, CL 8
Mixins & Software Components n Question n n If so, then mixins must support: n n n 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 n Variation can occur on many axes: n Client interface {get. Song, put. Song, erase. Copyright, hide. Britney, …} n Server execution strategy {single threaded, thread-spawning, thread pool, …} n n Fault tolerance n Server discovery n 12/7/00 Transport type … Java Layers/RC, CL 10
Music Application Instances Simple No. Britney Base Get. Song Erase. Copyright Put. Song Get. Song Hide. Britney Thread. Spawn leaf-types 12/7/00 Java Layers/RC, CL Thief … 11
Application Assembly is Easy class Simple extends Put. Song
Base Class class Base { static public class Client {…} static public class Server { void dispatch. Loop(){for(; ; ) dispatch(read. Request()); } void dispatch(Req req){error. Unknown. Req(req); } … } } 12/7/00 Java Layers/RC, CL 13
Get. Song Mixin constraint nested mixins class Get. Song
Other Mixins class Erase. Copyright
Stepwise Program Refinement class Thief extends Thread. Spawn
Drawbacks of Mixins n Superclass initialization n Runtime efficiency n Leaf-type references n Composition validation n n 12/7/00 Semantic validity Syntactic correctness Java Layers/RC, CL 17
Recap n Software components imply reuse n Mixins reuse OO code n Mixins build applications incrementally n n Nested types encapsulate features n n Stepwise program refinement Feature mixing and matching Mixins have usability & efficiency drawbacks 12/7/00 Java Layers/RC, CL 18
Part II – Java Layers n Java Layers Overview n Two JL Language Features n Status n Conclusion 12/7/00 Java Layers/RC, CL 19
Goal of Java Layers n Increase software reuse to reduce development and maintenance costs n Use layered, stepwise program refinement n Encapsulate features in mixins classes n Compose features through type instantiation 12/7/00 Java Layers/RC, CL 20
JL’s Foundation n Java + Constrained Parametric Polymorphism (CPP) n There are several proposals for adding CPP to Java [Agesen 97, Bokowski 98, Bracha 98, Cartwright 98, Myers 97, Solorzano 98] n JL is a heterogeneous implementation of CPP n Conventional syntax and semantics n Parametric classes and interfaces n Mixins 12/7/00 Java Layers/RC, CL 21
The JL Language JL is a parametric Java plus 4 features: n Deep conformance n Static virtual typing n Semantic checking n Constructor propagation All language extensions are designed to support stepwise refinement 12/7/00 Java Layers/RC, CL 22
JL Compiler Support n Class hierarchy optimization n Remove design-time layering from runtime code n Inline calls to superclass methods w/same signature n 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 {…} n Java supports shallow type checking n n Answer: Maybe Interfaces and classes JL adds support for deep type checking n 12/7/00 Supertypes are checked for required nested types Java Layers/RC, CL 24
Deep Conformance n Deep Conformance supports stepwise refinement n Enforces structural conformance at all nesting depths n Subtypes can safely refer to nested types in their supertypes n Feature composition is enhanced by added type precision 12/7/00 Java Layers/RC, CL 25
Deep Conformance Example class Hide. Britney
Deep Conformance Syntax n Deeply modifier for implements and extends clauses n n n Different meaning in constraint and inheritance clauses Operates on public nested types by default Propagate modifier for non-public nested types n n 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 Double. Node extends Node {Double. Node prev; } class Double. Node extends Node {typedef Node as Double. Node; Double. Node prev; } n In Double. Node: n next is type Node n next is type Double. Node n prev is type Double. Node [Thorup 97] 12/7/00 Java Layers/RC, CL 28
Virtual Types n The automatic adaptation of types through inheritance. n n n Virtual types change through subtyping A child class can change the type of its parent Benefits of Virtual Typing n Greater type precision n Better type checking n Less manual typecasting n Genericity (Beta) 12/7/00 Java Layers/RC, CL 29
JL’s This Virtual Type n This pseudo-type is like the “type of this. ” n Static binding n n n Used in parametric types only Bound at instantiation time Enhances JL’s expressiveness n 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 Client. Factory
Work Completed n Implemented JL prototype n Compared JL to OO Frameworks n Reengineered Schmidt’s ACE n ICSE 2001 paper 12/7/00 Java Layers/RC, CL 32
Future Work n Develop new JL compiler n n Implement language described here Build a family of related applications n 12/7/00 Compare JL and OO approaches Java Layers/RC, CL 33
Related Work n Gen. Voca – Batory 92 -00, Smaragdakis 98 -99 n Parametric Polymorphism – Agesen 97, Bokowski 98, Bracha 90, Bracha 98, Cartwright 98, Myers 97, Solorzano 98 n Virtual Types – Bruce 97 -98, Madsen 89, Thorup 97, Thorup 99, Torgerson 98 n Semantic Checking – Batory 95, Perry 89 -93 n Programming Paradigms – Danforth 98, Gamma 94, Harrison 93, Johnson 91, Kiczales 97, Schmidt 98, Tarr 99 12/7/00 Java Layers/RC, CL 34
Conclusion n JL extends Java to improve reusability n n Assembles applications from reusable parts n Builds on parametric polymorphism n n Promotes stepwise program refinement 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