BoxScript: A Component-Oriented Language for Teaching

Download Report

Transcript BoxScript: A Component-Oriented Language for Teaching

Java in the Box:
Implementing the BoxScript
Component Language
Yi Liu
Electrical Engineering and Computer Science
South Dakota State University
H. Conrad Cunningham
Computer and Information Science
University of Mississippi
Software Components
2
Components – A Closer Look
required
provided
required
provided
interface
inner
component
Component1
Component2
3
A Simple Example
Storage
Pricing
Storage
Discounting2
Discounting
Discounting2
Discounting
CalPrice
Pricing
Compositionality
Flexibility
4
Key Concepts
Interface

Interface (type)
– Java interface gives operation signatures
Price.java
public interface Price
{ double getPrice(int client, int item, int quantity);
}

Provided interface
– describes operations the component implements that
other components may use

Required interface
– describes operations the component uses that must be
5
implemented by another component
Key Concepts
Box

A box is a component
– whose description includes provided and required
interfaces
– has 1..n provided interfaces
1…n
– has 0..m required interfaces
P1
Pn

…
Boxes may be
– abstract
– concrete


atomic
compound
Box
…
R1
Rn
0…m
6
Key Concepts
Abstract Box

Abstract box
– does not implement provided interfaces
– implemented by concrete boxes
Interface type
PricingAbs.box
Interface Price
abstract box PricingAbs
Pr
Handle
{ provided interface Price Pr;
PricingAbs
required interface Discount Dc,
Dc
PrRt
PriceRetrieve PrRt;
PriceRetrieve Discount
7
}
Key Concepts
Concrete Box

Atomic box
– does not contain any other boxes
– implements the provided interfaces
Price
Pricing.box
Pr
box Pricing implements PricingAbs
Pricing
{ provided interface Price Pr;
Dc
PrRt
required interface Discount Dc; PriceRetrieve Discount
}
Interface type
Interface
handle
8
Key Concepts
Interface Implementation for Atomic Box
PrImp.java
Price
Pr
public class PrImp implements Price
{ private BoxTop _box;
Pricing
Discount dc; // required interface
PriceRetrieve prRt; //required interface
Dc
PrRt
public PrImp(BoxTop myBox)
PriceRetrieve Discount
{ _box = myBox;
InterfaceName name = new InterfaceName("Dc");
dc
= (Discount)_box.getRequiredItf(name);
name = new InterfaceName(“PrRt");
prRt = (PriceRetrieve)_box.getRequiredItf(name);
}
public double getPrice(int client,int item,int quantity)
{ double price = prRt.itemPrice(item);
double disc = dc.getDiscount(client, item, quantity);
return price * (1 – disc * 0.01) * quantity;
9
}
}
Key Concepts
Compound Box

Compound box
– Composed from atomic boxes or other
compound boxes
– Follows composition rules
hide provided interfaces unless explicitly exposed
 must expose required interface of constituent
unless connected to provided interface of another
constituent

10
Key Concepts
Compound Box Example
box handle
box CalPrice implements CalPriceAbs
{ composed from PricingAbs boxP, DiscountingAbs boxD, StorageAbs boxS ;
provided interface Price tPrice from boxP.Pr;
connect boxP.Dc to boxD.Dis, boxP.PrRt to boxS.PrRt;
}
Price
tPrice
Discount
Price
Pr
Dis
PricingAbs
boxP
PriceRetrieve
PrRt
Dc
Discount
DiscountingAbs
boxD
PriceRetrieve
PrRt
StorageAbs
boxS
CalPrice
11
Key Concepts
Box Variant

Box variants
–
–
–
–
Enable flexibility
Implement same (parent) abstract box
Can be substituted for each other
Conform to their (parent) abstract box
provide at least the provided interfaces of parent
 require at most the required interfaces of parent

12
Key Concepts
Box Conformity
Suppose
 IP2’ extends IP2
 IR1’ extends IR1
IP1 IP2’ IP3
P1
P3
P2
Provided
interfaces
IP1 IP2
P1
B
R1
R2
IR1
P2
BAbs
IR2
Required R1
R2
R3
interfaces
IR1’ IR2 IR3
B conforms to BAbs
13
BoxScript Implementation
Box Source Code and Compilation

For all boxes
– interfaces (.java)
– box description (.box)

by user
by user
For atomic boxes only
– interface implementation (.java) by user

For concrete boxes only
– configuration information (.conf) by user
– box manager code (.java)
by compiler
Box code
BoxCompiler
Java code
Java Compiler
14
BoxScript Implementation
Box Manager Implementation

package declaration
– define filesystem usage

import
– interface declarations
– data type declarations

B.java
variable declarations
– instance variables for class

Box manager
class definition
Concrete Box B
15
BoxScript Implementation
Box Runtime Structure
<<interface >>
Price
references
implements
Lazy instantiation
<<Java class >>
CalPrice
constructor CalPrice
<<Java class >> instantiates <<Java class >>
Pricing
PrImp
instantiates
Pricing
constructor Pricing
instantiates
Discounting
<<interface >>
Discount
implements
<<Java class >> instantiates <<Java class >>
Discounting
DisImp
constructor Discounting
references
16
BoxScript Implementation
Box Manager Code

Generated by compiler
– to instantiate box instances
– to assign references to interface handles
17
BoxScript Implementation
Box Manager Implementation

Supports lazy instantiation
– BoxTop
BoxTop
BoxTop()
void setProvInterfacceDsc(InterfaceDsc pItfDsc)
void setRequInterfaceDsc(InterfaceDsc rItfDsc)
Object getProvidedItf(InterfaceName name)
Object getRequiredItf(InterfaceName name)
void setRequiredItf(InterfaceName iname, Object objRef)
18
BoxScript Implementation
Box Manager Implementation

Code generation
generateCode (B’dscFile, mngFile) //mngFile : filename for box manager
read in dscFile
genPackage();
genImports();
genVars();
genConstructor();
genGetProvidedItf(); // generate overriding method getProvidedItf
if B is compound
genSetRequiredItf(); // generate overriding method
setRequiredItf
writeIntoFile(mngFile);
19
Conclusion

Component-oriented programming
language BoxScript
– Builds upon Java
– Provides novel concepts of
box type structure
 box variants
 box conformity
 interface satisfaction

to support composition and flexibility
20
Questions
21